开发者

C# Bind value of datagridview column to DataTable

I have a DataTable as a data source of a GridView. I'm adding a combo box the the GridView .

I'd like to be able to add a column to the DataTable that would automatically updat开发者_如何学Pythone with the value the user selects in the GridView. Can anyone help?


and the answer is...

DataTable myTable = getYourDataByMagic();

DataGridViewComboBoxColumn box = new DataGridViewComboBoxColumn();
BindingSource bs = new BindingSource();
bs.add("choice one");
bs.add("choice two");

box.HeaderText = "My Choice";
box.Name = "select";
box.DataSource = bs;
box.DataPropertyName = "select";

myTable.Columns.Add(new DataColumn("select"));
this.dataGridView1.Columns.Add(box);
this.dataGridView1.DataSource = myTable;

now, your "myTable" will update with the values selected in the combobox


I'd put two grids side by side one containing all info and one that just had the blank column. I would update the datatable with the grid that contained the one column. This would be update based on selected index of the previous grid. First thing to come to mind.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜