public void update(List <AccountingItem> pRecordList) { if (InvokeRequired) { BeginInvoke(new updateDelegate(update), new object[] { pRecordList }); return; } int lLastPosition = -1; int lLastRowIndex = -1; int lSelectedIndex = -1; /* * Remember last position */ lLastPosition = DGV_TrafficData.FirstDisplayedScrollingRowIndex; lLastRowIndex = DGV_TrafficData.Rows.Count - 1; if (DGV_TrafficData.CurrentCell != null) { lSelectedIndex = DGV_TrafficData.CurrentCell.RowIndex; } try { DGV_TrafficData.SuspendLayout(); cAccountingRecords.Clear(); foreach (AccountingItem lTmp in pRecordList) { cAccountingRecords.Add(lTmp); } } catch (Exception) {} // Reset position try { if (lLastPosition >= 0) { DGV_TrafficData.FirstDisplayedScrollingRowIndex = lLastPosition; } } catch (Exception) { } // Selected cell/row try { if (lSelectedIndex >= 0) { DGV_TrafficData.CurrentCell = DGV_TrafficData.Rows[lSelectedIndex].Cells[0]; } } catch (Exception) { } DGV_TrafficData.ResumeLayout(); DGV_TrafficData.Refresh(); }