c# - How to fix 'System.OutOfMemoryException' occurred in mscorlib.dll after unison scrolling -
i have 2 datagriviews, requirements both datagriviews need scroll in unison allow user able see ‘input’. clarify:
- i create new file browsing original file,
- when loads (grid1) loads 1 grid being empty (grid2) i'm able input grid2.
all menotined above working fine can save , edit file. created unison scrolling scrolls 1 row , throws error below,
error: unhandled exception of type 'system.outofmemoryexception' occurred in mscorlib.dll
scrolling code,
private void gridview1_scroll(object sender, scrolleventargs e) { foreach (datagridviewrow _row in gridview1.rows) { (int n = 0; n < gridview1.columns.count; n++) { gridview1.scroll += new system.windows.forms.scrolleventhandler(gridview1_scroll); //it throws error here. } } foreach (datagridviewrow _roww in gridview2.rows) { (int nn = 0; nn < gridview2.columns.count; nn++) { gridview2.firstdisplayedscrollingrowindex = gridview1.firstdisplayedscrollingrowindex; } } }
move part:
gridview1.scroll += new system.windows.forms.scrolleventhandler(gridview1_scroll);
to form's constructor. loops unnecessary (the code not depend on loop variables _row
, n
).
also, in part:
foreach (datagridviewrow _roww in gridview2.rows) { (int nn = 0; nn < gridview2.columns.count; nn++) { gridview2.firstdisplayedscrollingrowindex = gridview1.firstdisplayedscrollingrowindex; } }
loops not needed. part:
gridview2.firstdisplayedscrollingrowindex = gridview1.firstdisplayedscrollingrowindex;
will work - note not depend on loop variables _roww
, nn
.
Comments
Post a Comment