Winforms C# DatagridviewcomboboxColumn

G

Giri Palakodeti

I have a DataGridView which was bound to a datasource. At run time I added a
new DataGridViewComboBoxColumn and populate the Combo with a DataTable.
I can now save the GridColumns + ComboBox Column to a SQL database when user
clicks a button.

The Problem is when I revisit the FORM I want to pull the datatable and bind
to the DataGrid. I could do this succesfully but for one thing. I can set the
VALUE of the combobox column from the DataTable. But is is not showing the
TEXT or i would say the selectedindex is not moving to the value I got from
the DataTable

Sample Code

DataTable dt1 = dsGrids.Tables[0];
int i = 0 ;
foreach (DataRow dr in dt1.Rows)
{
System.Data.DataRow[] Model = dsServers.Tables[0].Select("ID='" +
dr["Model"].ToString() + "'");
DataGridViewComboBoxCell cb = (DataGridViewComboBoxCell) dgServers[0,i] ;
// Here I could set the value but not TEXT. The Combo should show up
corresponding DisplayMember or text
cb.Value = Model[0][0].ToString() ; // this is VALUE and
Model[0][1].ToString() is TEXT
i = i+1 }
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top