[英]An exception of type 'System.OutOfMemoryException' occurred in mscorlib.dll but was not handled in user code, while creating json file
[英]How to fix 'System.OutOfMemoryException' occurred in mscorlib.dll after unison scrolling
我有兩個datagriview,要求兩個datagriview必須一致滾動,以使用戶能夠看到“輸入”。 澄清:
我可以保存和編輯文件,上面所有經過優化的工作都很好。 我創建了統一滾動,但只滾動了一行,並在下面拋出錯誤,
錯誤: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;
}
}
}
移動此部分:
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
工作-請注意,它也不依賴於循環變量_roww
和nn
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.