【问题标题】:Odd DataGridView vertical scrolling behavior奇怪的 DataGridView 垂直滚动行为
【发布时间】:2011-06-30 18:42:20
【问题描述】:

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

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

这可能是什么原因。我需要某种 BeginUdateSuspendLayout 之类的吗?该控件通过互操作嵌入到 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


    【解决方案1】:

    我遇到了同样的问题,发现当我在代码中而不是在设计器中设置 DataGridView 的滚动条属性时,它工作得很好。所以我有一些类似的东西:

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

    不知道为什么它会起作用:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-08
      • 1970-01-01
      • 2012-09-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多