Combobox in bound DataGridView

Posted by Dan on Stack Overflow See other posts from Stack Overflow or by Dan
Published on 2010-05-29T18:06:12Z Indexed on 2010/05/29 18:12 UTC
Read the original article Hit count: 463

Filed under:
|
|
|

Hi. I've got a DataGridView control which is bound to a database table. I want one of the columns in the gridview to be of combobox type. The combobox should contain a list of hardcoded strings, which is the same for all rows in the datagridview. One of the fields in my database table is an index for this list of hardcoded strings.

I've programatically added a new column to the gridview of type "DataGridViewComboBoxColumn", which successfully creates the column with comboboxes in it. However, that's then not bound to the index field in my DB table.

The index field in my DB table is actually automatically bound to a column via the DataAdapter::Fill method. I've set this column to hidden, so it's hidden to the user.

Obviously just before updating the dataadapter, I can programatically fixup the hidden column in my datatable with the SelectedIndex of my combobox. Just wondering if there's a better way of doing this?

Thankyou for any help with this,
Dan.

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET