I have a data entry form that stores the rows displayed in the datagridview to a Datatable. I want to use this table to determine if the user has added, deleted rows, or changed the values in any fields. I am sorry if I have asked this before. I know I have researched it several times. At this point I have been playing with the code below. I assume I need to loop through the DGV and check the Shift_Key and Printer_ID to make sure I am comparing the same rows. In the old days of linear programming I would use a loop with Get_Next until the end of both tables were reached. Now in C# with databinding I don't have a clue? I will keep trying but if someone has a way to do this "ie Validate changes in a DGV" please share. Thanks
private void LoadList(int Shift_Key)
{
// Get the table from the data set
SqlConnection conn = new SqlConnection(Properties.Settings.Default.LazerMaintenance_Conn);
string queryString = "SELECT * FROM dbo.Shift_Printers WHERE Shift_Key = " + Shift_Key + ";";
conn.Open();
using (SqlDataAdapter comm = new SqlDataAdapter(queryString, conn))
{
// Adapter fill table function
comm.Fill(tab);
}
conn.Close();
}
private void dgvShift_Printers_CurrentCellDirtyStateChanged(object sender, EventArgs e)
{
// Then when the first character is typed
//
MessageBox.Show("Dirty changed");
if (dgvShift_Printers.IsCurrentCellDirty)
{
MessageBox.Show("Dirty changed = " + dgvShift_Printers.CurrentCell.OwningColumn.Name);
//dgvShift_Printers.CommitEdit(DataGridViewDataErrorContexts.Commit);
}
}
private int count;
private void dgvShift_Printers_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
// This hits once gor each cell on entry
// The below chech keeps form executing code in block on start up
count += 1;
if (dgvShift_Printers.CurrentCell != null)
{
MessageBox.Show("Cell changed = " + dgvShift_Printers.CurrentCell.OwningColumn.Name);
}
}