Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Bind Data to DataGridView With Combobox Columns

$
0
0

OK, so I am currently binding data to a datagridview without any issue, where the columns were text fields. I've now been asked to add two combobox columns (which i have been able to bind data to successfully - each contains a defined key/value pair), but what I'd like to do, is when I bind the overall data to the grid, for the values to be selected correctly in the combobox fields. I could iterate through the rows and set the data, following the binding (BindingComplete event) but wondered if it's possible to, when binding the actual data to the grid, for it to select the appropriate values in the lists for each row.

So, for example:

ComboBoxColumn1:=

ValueMember of 1, DisplayMember of "Apples"
ValueMember of 2, DisplayMember of "Pears"
ValueMember of 3, DisplayMember of "Grapes"

ComboBoxColumn2:=

ValueMember of 1, DisplayMember of "Tomatoes"
ValueMember of 2, DisplayMember of "Carrots"
ValueMember of 3, DisplayMember of "Potatoes"
ValueMember of 4, DisplayMember of "Swede"
ValueMember of 5, DisplayMember of "Parsnips"

When I load my data from the database, the columns that will be bound to the combobox columns contain the IDs from the appropriate table, so would look something like:
"Mr Smith", 2, 5
"Mrs Jones", 1, 3
"Mr Thomas", 3, 1
and so on

So I can bind the data into the combobox columns first, but can I then bind, over the top, the data that will set the relevant items in each row?

Thanks

Martin



Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>