datagridview

DataGridView setting Row height in code and disable manual resize

﹥>﹥吖頭↗ 提交于 2019-12-30 02:45:11
问题 In my grid I had following line of code which disabled user's manual resizing: dgvTruckAvail.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells; Now I needed to set column height in code and it didn't work (see DataGridView setting row height doesn't work) I figured that it was this line of code that caused non-sizing issue. However, now I need to figure out how to Size rows in code and Prevent user sizing rows themselves Any pointers? 回答1: Set: dgvTruckAvail.AutoSizeRowsMode =

Programmatically resize DataGridView to remove scroll bars

早过忘川 提交于 2019-12-30 02:15:30
问题 I have a DataGridView with a user definable number of columns (anywhere from ~6-60) of numerical data. At the higher end that amount of data in the grid exceeds that which can be displayed on screen at once. I have a graph that goes with the data. I would like to keep the two in sync, so that a specific time T on the graph is in line vertically with the same time in the grid. To do this I'd like to make the DGV just wide enough to avoid a horizontal scroll bar, have the graph be equally wide,

DataGridView become ReadOnly with Linq using c#

只愿长相守 提交于 2019-12-29 09:18:30
问题 I am implementing a system using C# ( Windows Forms ) with Entity Frame work and Linq. The DataGridView works well when using normal linq statement, but when I used "Join", the DataGridView Become read Only and I cant edit anything. Example: DataGridView work well with this statement : var query = from d in db.Device select d; dgvDevices.DataSource = query.ToList(); but it become non-editable with this query : var query = from u in db.Users join d in db.Device on u.id equals d.AssignedTo

InvalidOperationException - When ending editing a cell & moving to another cell

我们两清 提交于 2019-12-29 09:01:55
问题 I made a program in which I wanted to manually update the Data Grid View. -I have a Method to Refresh the DGV by clearing it and then reinserting the data. -Using the designer, I made an event handler for the DGV's CellEndEdit. Inside the Event Handler, the data gets updated & the DGV's custom refreshing method is called. While running the program, whenever I start editing a cell & end it by selecting another one, an exception is thrown: InvalidOperationException Operation is not valid

How to programmatically add a row to a datagridview when it is data-bound?

喜夏-厌秋 提交于 2019-12-29 08:42:10
问题 How can I add a row to a datagridview control if it is bounded to a datasource (datatable) ? Thanks! 回答1: Add a row to the datatable, the datagridview will update automatically: DataTable dt = myDataGridView.DataSource as DataTable; //Create the new row DataRow row = dt.NewRow(); //Populate the row with data //Add the row to data table dt.Rows.Add(row); 回答2: Create a class that corresponds to the data you want to display in your grid (same properties) In your data-binding function, get your

How to find the actual width of grid component with scrollbar in Delphi

元气小坏坏 提交于 2019-12-29 08:08:10
问题 I have a grid component (DBGrid) which has lots of columns on it. Because of large number of columns, a scrollbar was created, and thus some part of grid remains hidden. I need to find out what is the real width of DBGrid, including the part which is not shown due to scroll bar. But Width property gives only the width of the component itself. Anybody has any idea? 回答1: Perhaps this may be helpful. It is part of a class helper for TDBGrid that auto sizes the last column, so that the grid has

How to synchronize Database and DataGridView

隐身守侯 提交于 2019-12-29 08:07:50
问题 I have been trying to synchronize a database trough a DataGridView . So far I have created a data model class. This class contains multiple Properties that match the database. They are mapped using the [Table] and [Column] attributes from the System.Data.Linq.Mapping namespace. Ok. So I bound the DataGridView using the DataSource -Property to a DataContext connecting to the Database (MSSQL). This Logic is implemented in a singleton class, so I can assure there is a single instance of this

How to synchronize Database and DataGridView

*爱你&永不变心* 提交于 2019-12-29 08:07:10
问题 I have been trying to synchronize a database trough a DataGridView . So far I have created a data model class. This class contains multiple Properties that match the database. They are mapped using the [Table] and [Column] attributes from the System.Data.Linq.Mapping namespace. Ok. So I bound the DataGridView using the DataSource -Property to a DataContext connecting to the Database (MSSQL). This Logic is implemented in a singleton class, so I can assure there is a single instance of this

skip first row in read of Excel file

故事扮演 提交于 2019-12-29 06:29:32
问题 Hello I'm trying to translate an Excel file to my dataGridView and it's having column name issues because the way the Excel file is formatted, there are two setup cells for the rest of the document. However the Column names are actually on Row #2. How can I skip the first row in the file read so that the Columns in the dataGridView show the cell values from the second row? Current code: var connectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0; data source={0}; Extended

skip first row in read of Excel file

别来无恙 提交于 2019-12-29 06:28:29
问题 Hello I'm trying to translate an Excel file to my dataGridView and it's having column name issues because the way the Excel file is formatted, there are two setup cells for the rest of the document. However the Column names are actually on Row #2. How can I skip the first row in the file read so that the Columns in the dataGridView show the cell values from the second row? Current code: var connectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0; data source={0}; Extended