c# - DataTable.Columns[0].Container returning null -


i'm trying bind datagridviewcomboboxcolumn object column in datatable binded datagridview. column placed separate datagridview. section of code happens:

//create material datatable materialtable = new datatable(); materialtable.columns.add("material", typeof(string));  datagridviewmaterials.datasource = materialtable;  //create material combobox column materialcolumn = new datagridviewcomboboxcolumn(); materialcolumn.datapropertyname = "material"; materialcolumn.name = "material"; materialcolumn.datasource = materialtable.columns[0].container; 

materialtable.columns[0].container; returns null no matter how populated materialtable is. other methods such materialtable.rows[0]["material"].tostring() works expected. how can work?

the columns collection represent constituent structure of datatable (aka schema). doesn't contains data. datatable , rows collection contains data. in case should write

//create material combobox column materialcolumn = new datagridviewcomboboxcolumn(); materialcolumn.datapropertyname = "material"; materialcolumn.name = "material"; materialcolumn.datasource = materialtable; 

of course, datatable should loaded data before appears in combobox.
example add

materialtable = new datatable(); materialtable.columns.add("material", typeof(string)); datarow row = materialtable.newrow(); row[0] = "first item"; materialtable.rows.add(row); 

or use specific sql classes load data, question


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -