winforms - Set default value to DataGridViewComboBoxColumn cells after using DataGridView.DataSource C# -


this question has answer here:

i trying add new column datagridview combobox. , set ever new cell default value. list of combobox updated fine, can't see default value...

this code :

            batteryinformationtests = databasemanager.getcatalogpropsbycatalognumber(catalognumber);             batteryinformationtestsdatagridview.datasource = batteryinformationtests;              datagridviewcomboboxcolumn cmbcol = new datagridviewcomboboxcolumn             {                 name = "propname",                 datapropertyname = "propname"             };              cmbcol.items.addrange(new object[] { "1", "2", "3" });              batteryinformationtestsdatagridview.columns.add(cmbcol);              foreach (datagridviewrow row in batteryinformationtestsdatagridview.rows)             {                 row.cells["propname"].value = "2";             } 

batteryinformationtests

private datatable batteryinformationtests; 

this how looks after running http://prntscr.com/gk3890.

also when chose combobox can see correct list of values. http://prntscr.com/gk3acn

i found when remove line

batteryinformationtestsdatagridview.datasource = batteryinformationtests; 

it solve problem datagridview empty bacouse no datasource ther...

what best way solve problem?

moving batteryinformationtestsdatagridview.datasource = batteryinformationtests; line before manual add might solve problem told didn't work. solution assigning nullvalue,

datagridviewcomboboxcolumn cmbcol = new datagridviewcomboboxcolumn {      name = "propname",      datapropertyname = "propname" }; cmbcol.defaultcellstyle.nullvalue = "2"; 

hope helps,


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -