Bob Coder
Bob Coder

Reputation: 401

datagridviewcomboboxcolumn databinding

I have a datagridviewcomboboxcolumn (ComboCol), that i add programmicaly to a datagridview.

I want my ComboCol to display in its dropdown the items of a IList, AND when an item from that list is selected, to assign that value to the property of an object on a different IList.

Is this possible? All I have been able to get so far is only half of the job. I can display the items of a particular list by setting it as a datasource, but when the item is selected i need to programicaly assign the proper value to the desired object. Is there no way to do this automatically?

BTW, if I add the ComboCol to the datagridview, and then set the datagridview's datasource, how does this affect the databinding of the ComboCol?

Upvotes: 0

Views: 839

Answers (1)

Bob Coder
Bob Coder

Reputation: 401

Ok, so here is the answer.

In pseudocode:

List PossibleValues

List BoundObjects

ComboCol.ValueMember --> Set to name of property of class in PossibleValues ComboCol.DataPropertyName --> Set to name of property of class in BoundObjects ComboCol.DisplayMember --> Set to name of property of class in PossibleValues you wish to display

DataGrid.Add(ComboCol)

ComboCol.DataSource = PossibleValues
DataGrid.DataSource = BoundObjects

Upvotes: 1

Related Questions