datagridview

How can you make a DataGridView scroll one item at a time using the mouse wheel?

We'd like to override DataGridView's default behavior when using a mouse wheel with this control. By default, the DataGridView scrolls a number of rows equal the SystemInformation.MouseWheelScrollLines setting. What we'd like to do is scroll just one item at a time. (We display images in the DataGridView, which are somewhat large. ...

Adding rows to datagridview with existing columns

I have a datagridview with several columns created. I add some rows and they get added correctly, but when i click on the cells, the content disappears... (?!) Edit: This is WinForms What am I doing wrong? The code is as follows: foreach (SaleItem item in this.Invoice.SaleItems) { DataGridViewRow r...

C# ResetBinding flip the DataGridView *Updated with example*

I had a problem that was partially solved. To explain it quickly : I have a grid binded to a complex object that require to be serialized. When the object is build back from the serialization, event like on the grid doesn't refresh the table display. Someone told me to rebuild the event once unserialize, it works! But the event that refr...

DataGridView's bound table only generates one RowChanged event on a double-click. How do I make it do two?

I have a DataGridView whose DataSource is a DataTable. This DataTable has a boolean column, which is interpreted as a checkbox in the DataGridView. employeeSelectionTable.Columns.Add("IsSelected", typeof(bool)); ... employeeSelectionTable.RowChanged += selectionTableRowChanged; dataGridViewSelectedEmployees.DataSource = employeeSelectio...

Customized DataGridView column does not accept the entered decimal seperator under Windows Vista

Hello everybody! For a project I built a custom DataGridView column which contains NumericUpDown controls. It is implemented similar to the suggestion from Microsoft The column works fine under Windows XP. It accepts the entered digits and decimal separator. Under Windows Vista I have the odd problem that the control only accepts the d...

How can I export the data in a DataGridView data to an Excel spreadsheet?

In my Winforms application, I want to export the data from my DataGridView to a Excel spreadsheet. Is it simply a job of looping and outputting the results comma seperated? ...

Right-click to select a datagridview row.

How do you select a datagridview row on a right-click? ...

Display an invalid default value in a DataGridViewComboBoxColumn

I have a DataGridViewComboBoxColumn in a DataGridView in a windows application. The user can change settings elsewhere to potentially invalidate a selection in a DataGridViewComboBoxColumn. I have a requirement to retain/display the invalid item while only leaving valid items selectable in the list. Without correcting the selection an...

Remove Last Row Databound DataGridView C#

Thanks in advance for any help. I'm using VS 2008/C# and binding a local List of helper classes as the DataSource for a DataGridView control. Calling the Remove() method on my List of helper classes fires the CellFormatting event of the DataGridView, which makes sense (a bit). But for some reason, when removing whatever happens to be ...

Why does my datagridview repositions on escape.

I have a DataGridView control on a form in a manged c# project. (.net 2.0) When I use the scroll button on my mouse and then click a cell and click the escape button or select another cell the grid will reposition it self. But if i use the scrollbar on the control, this behavior does not happen. Have anyone seen behavior like this befo...

DataGridView Mouse Selection

I am using a DataGridView control in a Windows Forms application. When a user holds down control to select multiple items, it works fine. Now when the user releases control and clicks (and holds down the left mouse button) to start a drag operation, the selection changes. How can I stop the selection from clearing when the user holds dow...

How to change the backcolor of a row in a DataGridView based on the value of a cell?

Say I have a DataGridView which shows the content of a DataTable. I want to be able to set the backcolor of a row based on the value of a cell in this row. Note that the cell in question is in a column which is not displayed in the DataGridView (Visible=False). ...

How to set selected row of DataGridView to newly-added row when the grid is bound to sorted DataView?

I have a DataGridView bound to a DataView. The grid can be sorted by the user on any column. I add a row to the grid by calling NewRow on the DataView's underlying DataTable, then adding it to the DataTable's Rows collection. How can I select the newly-added row in the grid? I tried doing it by creating a BindingManagerBase object boun...

What, if any, printable character did a user type based on the values in a given System.Windows.Forms.KeyEventArgs?

As a workaround for a problem, I think I have to handle KeyDown events to get the printable character the user actually typed. KeyDown supplies me with a KeyEventArgs object with the properities KeyCode, KeyData, KeyValue, Modifiers, Alt, Shift, Control. My first attempt was just to consider the KeyCode to be the ascii code, but KeyCod...

How to dynamically set which properties get bound to a DataGridView?

My DataGridView needs to support a number of types and these types may have any number of public properties, not all of which I want to display. Can anyone suggest a way to dynamically customise a DataGridView's columns when binding a class a datasource? Is there an attribute that will tell a control whether to use a property as a colum...

How can you get a ComboBox child of a DataGridView to process all keys, including "."?

I have the same problem as described in the posts listed below. That is, certain keys don't work at all when I type them into my combobox until I first hit the spacebar. One of the keys is ".", but another is the letter "Q", and there are others: "$", "%". http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=659716&SiteID=1 h...

How to change cell's ComboBox style in DataGridViewComboBoxColumn

Cells in DataGridViewComboBoxColumn have ComboBoxStyle DropDownList. It means the user can only select values from the dropdown. The underlying control is ComboBox, so it can have style DropDown. How do I change the style of the underlying combo box in DataGridViewComboBoxColumn. Or, more general, can I have a column in DataGridView with...

Raise CellValueChanged from a custom editing control in a DataGridView

I have a DataGridView (WinForms) in which I have defined a custom EditingControl derived from DataGridViewTextBoxEditingControl that only allows numeric characters. I need to raise CellValueChanged event on the DataGridView each time the user press a key, but the default behaviour is to raise the event only when edition has been complet...

How to make a ComboBox column with two data sources (for DataGridView)

The data sources have the same structure, but different data. One would be used for rows that are saved (view mode), and the other one would be for rows that are being added or edited (edit/new rows). How can that be acomplished? I have a standard foreign key column that references a standard lookup table which has an ID, Name and Activ...

how do I host a control in a DataGridViewCell for displaying as well as editing?

I've seen How to: Host Controls in Windows Forms DataGridView Cells which explains how to host a control for editing a cell in a DataGridView. But how can I host a control for displaying a cell? I need to display a file name and a button in the same cell. Our UI designer is a graphic designer not a programmer, so I have to match the c...