【发布时间】:2013-05-10 00:42:20
【问题描述】:
我使用通过绑定源绑定数据的 DataGridView。此外,我在最左边为用户创建了一个 CheckBoxCol。在那里选中复选框然后重新排序会使所有检查消失。有谁知道如何避免这种情况?
这里有一些代码,所以我们在同一页上;):
dtZg_Betr = new DataTable(); // DataTable object
// [...] SQL SELECT and so on, I cut that stuff a bit
adapter.Fill(dtZg_Betr); // OleDbAdapter -> fill the table with the SQL SELECT results
// [...]
bsZg_Betrn = new BindingSource(); // BindingSource object
bsZg_Betrn.DataSource = dtZg_Betr;
dgvZg_Betr.DataSource = bsZg_Betr; // bind data to DataGridView
DataGridViewCheckBoxColumn dgvCheckBox = new DataGridViewCheckBoxColumn();
dgvZg_Betr.Columns.Insert(0, (DataGridViewColumn)dgvCheckBox); // add additional checkbox column
// Later on somewhere else:
adapter.Update(dtZg_Betr); // OleDbAdapter -> update DB with table's changes
DataGridView 没有其他代码可以填充,当然稍后会处理复选框单击等,但这与问题无关。
问候!
【问题讨论】:
-
显示你已经完成的网格视图源代码
-
嘿伙计,我添加了几行和 cmets,因为我昨天快速复制了它们,但没有发现它们真的不够用,抱歉 ;)
标签: c# datagridview datasource bindingsource datagridviewcheckboxcell