我想删除所有行来重新加载它们(我需要删除所有行)由于某种原因,它不会从我的datagridview中删除它们(它不添加任何额外的任何)发生。我尝试了很多不同的方法,我知道我过去做过这些。 (也许是因为它的一天结束)从dataGridView使用数据删除行
这里是我的代码试图一大堆消除了
private void loadMSXGridView()
{
BindingSource bs = new BindingSource();
dgv.DataSource = null;
dgv.Refresh();
bs.DataSource = GetTable();
dgv.DataSource = bs;
dgv.Columns[0].Width = 391;
dgv.Columns[1].Width = 30;
}
private DataTable GetTable()
{
DataTable t = new DataTable();
t.Rows.Clear();
t.AcceptChanges();
t.Columns.Add("Accounting Line", typeof(string));
t.Columns.Add("#", typeof(string));
foreach (AMAPnr.RemarkElement re in AMAPnr._RemarkElements)
{
if (re.ElementID == "RM" && re.FreeFlow.StartsWith("*MS"))
{
DataGridViewCell gridCellText;
DataGridViewCell gridCellElement;
gridCellText = new DataGridViewTextBoxCell();
gridCellText.Value = re.FreeFlow;
gridCellElement = new DataGridViewTextBoxCell();
gridCellElement.Value = re.ElementNo.ToString();
t.Rows.Add(gridCellText.Value, gridCellElement.Value);
}
}
return t;
}
我的删除按钮调用loadMSXGridView,我只需要刷新一切,因为在我的datagridview的项目相关联以要素号,这将不会保持不变
为什么不使用另一个BindingSource并将它关联到网格? BindingSource bs = new BindingSource(); bs.DataSource = YourSource; dgv.DataSource = bs; – WorldIsRound 2011-03-16 22:15:14
@HelloWorld更新问题,我没有测试,因为它需要一段时间才能编译,只要它工作?或者我应该使用不同的方法 – Spooks 2011-03-16 22:19:42
我会试一试! – WorldIsRound 2011-03-16 22:22:38