I am using this code to delete a single selected row from the DataGridView as well as database
if (dgvTasks.SelectedRows.Count > 0)
{
DataGridViewRow currentRow = dgvTasks.SelectedRows[0];
int Serial = Convert.ToInt32(currentRow.Cells["Serial"].Value);
DialogResult response = MessageBox.Show("Are you sure you want to delete this row?", "Delete row?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
if ((response == DialogResult.Yes))
{
TaskDAL objTaskDal = new TaskDAL();
string message = objTaskDal.DeleteTask(connectionString, Serial);
if (message == "Yes")
{
BindTaskGrid();
}
}
}
Now in order to make multiple selected row I have to run a loop, which is something like this....
foreach (DataGridViewRow dgRows in dgvTasks.SelectedRows)
{
dgvTasks.Rows.Remove(dgRows );
}Now inside this loop I have to remove the date elements that are orignally stored in database also along with the row present in DataGridView. So how can i find out if that particular row is selected or not? How can I find the index of that selected row?
The loop can only runs for the number of row selected. The rows might be randomly selected, its not necessary that they will be in sequence?
Adeel