Winforms 奇怪的DataGridView垂直滚动行为

Winforms 奇怪的DataGridView垂直滚动行为,winforms,datagridview,Winforms,Datagridview,我有一个windows窗体DataGridView。我使用下面的代码来填充和更新,所有这些都非常简单,都是在UI线程上完成的 出于某种奇怪的原因,有时垂直滚动条的大小(我将其设置为仅在需要时可见)并不反映可用行的数量。如果我一直向下滚动,我仍然看不到最后几行。我可以通过使用向下箭头键选择下面的行(并将它们显示在视图中)来判断 这可能是什么原因呢。我需要某种开始日期或暂停布局或其他什么吗?该控件通过互操作嵌入到MFC应用程序中 安迪:你知道怎么解决这个问题吗?这是已知的bug吗?谷歌似乎不这么认为

我有一个windows窗体DataGridView。我使用下面的代码来填充和更新,所有这些都非常简单,都是在UI线程上完成的

出于某种奇怪的原因,有时垂直滚动条的大小(我将其设置为仅在需要时可见)并不反映可用行的数量。如果我一直向下滚动,我仍然看不到最后几行。我可以通过使用向下箭头键选择下面的行(并将它们显示在视图中)来判断

这可能是什么原因呢。我需要某种开始日期或暂停布局或其他什么吗?该控件通过互操作嵌入到MFC应用程序中

安迪:你知道怎么解决这个问题吗?这是已知的bug吗?谷歌似乎不这么认为

这是我使用的代码

添加或插入行:

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;
清除:

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;
更新行:

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;

我也有同样的问题,发现当我在代码中设置DataGridView的scrollbar属性而不是设计器时,它工作得很好。所以我有一些大致的想法:

foreach(Listitem item in list)
{
  //populate grid
}
dataGridView.ScrollBars = ScrollBars.Both;

但是,我不知道它为什么会工作:)

我也有同样的问题,发现当我在代码中设置DataGridView的滚动条属性而不是设计器时,它工作得很好。所以我有一些大致的想法:

foreach(Listitem item in list)
{
  //populate grid
}
dataGridView.ScrollBars = ScrollBars.Both;
但是,我不知道它为什么起作用:)