【发布时间】:2011-06-30 18:42:20
【问题描述】:
我有一个 Windows 窗体 DataGridView。我使用下面的代码填充和更新,所有这些都非常简单,并且都是在 UI 线程上完成的。
出于某种奇怪的原因,有时垂直滚动条的大小(我设置为仅在需要时才可见)并不能反映可用行的数量。如果我一直向下滚动,我仍然看不到最后一行。我可以通过使用向下箭头键选择下面的行(并将它们显示在视图中)来判断。
这可能是什么原因。我需要某种 BeginUdate 或 SuspendLayout 之类的吗?该控件通过互操作嵌入到 MFC 应用程序中。
Andy 知道如何解决这个问题?这是一个已知的错误? Google 不这么认为,似乎。
这是我使用的代码。
添加或插入一行:
int newRowIndex = insertAt;
if (insertAt < 0 || insertAt > this.dataGridView.Rows.Count)
{
newRowIndex = this.dataGridView.Rows.Add();
}
else
{
this.dataGridView.Rows.Insert(insertAt, 1);
}
删除一行:
this.dataGridView.Rows.Remove(index);
清算:
this.dataGridView.Rows.Clear();
更新一行:
this.dataGrid[0, rowIndex].Value = someString;
this.dataGrid[1, rowIndex].Value = someBool;
this.dataGrid[2, rowIndex].Value = someInt;
【问题讨论】:
标签: winforms datagridview