When the datagrid is first populated or refreshed, I pull the data from the database and and add a Changed column defaulted to False. That becomes the datasource for the Datagridview.
dadapt.Fill(lDT_transReview);
lDT_transReview.Columns.Add("Changed",typeof(Boolean), "false");
dgTransReview.DataSource = lDT_transReview;
To check if the date was actually changed (not just entering the same date), I store the original date in a temp variable on the begin edit event. Then on the end Edit event I compare the date and set a 'changed' boolean checkbox to true.
dgTransReview["Changed", e.RowIndex].Value = "True";
Then on the code to save the row, I'm using a foreach loop to see if the 'changed' column is true.
foreach (DataGridViewRow row in dgTransReview.Rows)
{
if (row.Cells["Changed"].Value.ToString() == "True")
{
//Code to save individual row with changes to database
}
}
TransRefresh();
The problem I'm getting is that the Changed cell does not appear to be keeping the value. when it gets to setting the value to True, the cells is Null before the update (but True after) and when I get to the foreach loop, I get an object not set error because the cell is null again.
ThomasPosted Apr 30, 2013, 12:51 PM
ThomasPosted Apr 30, 2013, 10:35 AM
the problem is that the Boolean field I'm setting if it changes does not appear to be saving any values or it is somehow being set to null.
vipul jainPosted Apr 30, 2013, 5:27 AM
.......
like
int n=0;
while(n
// write the update query which column you want to update in the database.
}..