How to know which row is edited in DatagridView

F

fiaolle

Hi
If a user changes to another row after he's been editing a row and clicks
the save button, how can I then know which row has been edited.
I have tried the code below, but it seems like setting a row's property
selected to true doesn't make the row to the current row.

if (dgvProcess.IsCurrentRowDirty)
{
Database.dp.UpdateCommand.Parameters["@oldProcessID"].Value
= dgvProcess.CurrentRow.Cells[0].Value;
Database.dp.UpdateCommand.Parameters["@Process"].Value
= dgvProcess.CurrentRow.Cells[1].Value;
Database.dp.UpdateCommand.Parameters["@ApproveLimit"].Value
= dgvProcess.CurrentRow.Cells[2].Value;
Database.dp.UpdateCommand.Parameters["@TimeLimit"].Value
= dgvProcess.CurrentRow.Cells[3].Value;
Database.dp.UpdateCommand.Parameters["@LastDay"].Value
= dgvProcess.CurrentRow.Cells[4].Value;
Database.dp.UpdateCommand.ExecuteNonQuery();
}
else
{
foreach (DataGridViewRow row in dgvProcess.Rows)
{
row.Selected = true;

if (row.DataGridView.IsCurrentRowDirty)
{
Database.dp.UpdateCommand.Parameters["@oldProcessID"].Value
= row.Cells[0].Value;
Database.dp.UpdateCommand.Parameters["@Process"].Value
= row.Cells[1].Value;
Database.dp.UpdateCommand.Parameters["@ApproveLimit"].Value
= row.Cells[2].Value;
Database.dp.UpdateCommand.Parameters["@TimeLimit"].Value
= row.Cells[3].Value;
Database.dp.UpdateCommand.Parameters["@LastDay"].Value
= row.Cells[4].Value;
Database.dp.UpdateCommand.ExecuteNonQuery();
}
}
}
Please help me

Fia
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top