2011-06-30 32 views
1

我有一个Windows窗体DataGridView。我使用下面的代码填充和更新,都非常简单,并且全部都是在UI线程上完成的。Odd DataGridView垂直滚动行为

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

这可能是什么原因。我需要某种开始日期SuspendLayout什么?该控件通过interop在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; 

回答

1

我有同样的问题,并发现,当我在代码中设置的DataGridView的滚动条属性,而不是设计师,它的工作就好了。所以我只是有几行内容:

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

不知道为什么但是它的工作:)