save to DB & update DT+DGV, vs Total UI requery from DB

Here’s code for this… save to database + update local datatable + update local datagridview = faster than refreshing UI from database

if (lblSerialNumberId.Text != “”)
{
MesQueries.SRUSheetCreation sru = new MesQueries.SRUSheetCreation(_mq);
string serial_number_id = lblSerialNumberId.Text;
string change_orders = txtChangeOrders.Text;
sru.SaveInspectionInfo(serial_number_id, change_orders);
// Save in local DataTable.
int rowNumToUpdate = -1;
for (int i = 0; i < _dtCHData.Rows.Count; i++)
{
if (_dtCHData.Rows[i][“serial_number_id”].ToString().Equals(serial_number_id))
{
rowNumToUpdate = i;
break; // early exit of for loop.
}
}
_dtCHData.Rows[rowNumToUpdate][“drawing_revision”] = drawing_revision;
_dtCHData.Rows[rowNumToUpdate][“change_orders”] = change_orders;

// Save in local datagrid for display to UI.
dgvSruSheet.Rows[_selectedGridRow].Cells[“drawing_revision”].Value = drawing_revision;
dgvSruSheet.Rows[_selectedGridRow].Cells[“change_orders”].Value = change_orders;

_flagDirtyData = false;
}

Possibly also useful:

DataTable.AcceptChanges(); //to force update of DataTable.

DataGridView.Invalidate() or InvalidateColumn(), …Row(), …Cell(). Or DataGridView.RefreshEdit(). Or, .UpdateCellValue().  I have not yet found which if any of these are functional.

This entry was posted in C#, Programming. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *