This project is read-only.

SourceGrid DataGrid with underlying Table, Is there a more efficient way to do this?

May 25, 2015 at 4:03 PM
Hi -

I have a sourcegrid datagrid with a table behind it. I have multiple threads (4) updating the backing table, and so - thus I have 2 copies of the table, and merge them from the UI thread.

Some things to note:

The table is guarded by a readerwritterlockslim. Lock contention doesn't seem to be an issue.
There is no database behind this table, its for display purposes only.
Only columns 3 or 4 can change during the times I care about performance-

With about 8000 rows, I see merge times (used high precision stopwatch to measure) of about 150 milliseconds average, 800 worst case when lots of cells change.

Would an arrayGrid be better here? Every column in the table does not have the same type, so I'm unsure how to do it properly;

I played with suspend / resume layout and Invalidate Range / Update (as shown below) but I saw worse results.

Thanks for any tips / input -

Code looks like the following:

Each Thread is doing this to update their rows -
private void UpdateGridStatusDataTableRow(int rowIndex, string stateString, string directionString)
        {
            _gridTableSlimLock.EnterWriteLock();

            DataRow row = _gridDatasetStatusTable.Rows[rowIndex];
            
            row.BeginEdit();
            row[3] = stateString;
            row[4] = directionString;
            row.EndEdit();

            _gridTableSlimLock.ExitWriteLock();
        }
About once per second, the merge is called from the main UI thread -
public void RefreshGrid()
{
      //expSetGrid.SuspendLayout();
      //expSetGrid.InvalidateRange(new Range(0, 3, _lastRow, 4));

      _experimentSet.MergeGridStatusDataTable(_gridSource);
            
      //expSetGrid.Update();
      //expSetGrid.ResumeLayout(false);
}

public void MergeGridStatusDataTable(DataTable uiDatatable)
 {
            _gridTableSlimLock.EnterWriteLock();
            uiDatatable.Merge(_gridDatasetStatusTable, false);
            //_gridDatasetStatusTable.AcceptChanges();
            _gridTableSlimLock.ExitWriteLock();
 }
The Grid is Initialized as follows:
           //Disable Constraints
            _gridSource.Constraints.Clear(); //DataTable

            _view = _gridSource.DefaultView; //DataView
            _view.AllowEdit = false;
            _view.AllowDelete = false;
            _view.AllowNew = false;
            
            _bdv = new BoundDataView(_view); //BoundDataView
            expSetGrid.DataSource = _bdv;    //SourceGrid.DataGrid