我有两个数据浏览,要求是两个datagriviews需要一致滚动才能让用户能够看到'Input'。澄清:
上面的所有内容都正常工作,因为我可以保存和编辑文件。我创建了unison滚动,但它只滚动一行并在下面抛出错误,
错误:mscorlib.dll中出现未处理的“System.OutOfMemoryException”类型异常
滚动代码,
private void Gridview1_Scroll(object sender, ScrollEventArgs e)
{
foreach (DataGridViewRow _row in Gridview1.Rows)
{
for (int n = 0; n < Gridview1.Columns.Count; n++)
{
Gridview1.Scroll += new System.Windows.Forms.ScrollEventHandler(Gridview1_Scroll); //it throws an error here.
}
}
foreach (DataGridViewRow _roww in Gridview2.Rows)
{
for (int nn = 0; nn < Gridview2.Columns.Count; nn++)
{
Gridview2.FirstDisplayedScrollingRowIndex = Gridview1.FirstDisplayedScrollingRowIndex;
}
}
}
答案 0 :(得分:0)
移动这部分:
Gridview1.Scroll += new System.Windows.Forms.ScrollEventHandler(Gridview1_Scroll);
到表单的构造函数。循环是不必要的(代码不依赖于循环变量_row
和n
)。
此外,在这部分:
foreach (DataGridViewRow _roww in Gridview2.Rows)
{
for (int nn = 0; nn < Gridview2.Columns.Count; nn++)
{
Gridview2.FirstDisplayedScrollingRowIndex = Gridview1.FirstDisplayedScrollingRowIndex;
}
}
不需要循环。这部分:
Gridview2.FirstDisplayedScrollingRowIndex = Gridview1.FirstDisplayedScrollingRowIndex;
将自行运行 - 请注意,它也不依赖于循环变量_roww
和nn
。