Rahamathulla_J
asked on
datagridview row deleting
In Datagridview if the user clicks the delete button the rows are deleting? How can i avoid that?
Oops, now an example in c#
private void DataGridView1_UserDeleting Row(object sender,
DataGridViewRowCancelEvent Args e)
{
DataGridViewRow startingBalanceRow = DataGridView1.Rows[0];
// Check if the Starting Balance row is included in the selected rows
if (DataGridView1.SelectedRow s.Contains (startingB alanceRow) )
{
// Do not allow the user to delete the Starting Balance row.
if (e.Row.Equals(startingBala nceRow))
{
MessageBox.Show("Cannot delete Starting Balance row!");
}
// Cancel the deletion if the Starting Balance row is included.
e.Cancel = true;
}
}
http://msdn2.microsoft.com/en-us/library/system.windows.forms.datagridview.userdeletingrow.aspx
private void DataGridView1_UserDeleting
DataGridViewRowCancelEvent
{
DataGridViewRow startingBalanceRow = DataGridView1.Rows[0];
// Check if the Starting Balance row is included in the selected rows
if (DataGridView1.SelectedRow
{
// Do not allow the user to delete the Starting Balance row.
if (e.Row.Equals(startingBala
{
MessageBox.Show("Cannot delete Starting Balance row!");
}
// Cancel the deletion if the Starting Balance row is included.
e.Cancel = true;
}
}
http://msdn2.microsoft.com/en-us/library/system.windows.forms.datagridview.userdeletingrow.aspx
Why don't you disable deleting rows in that datagridview ?
ASKER
Is there any property for that if so no problem for me
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The UserDeletingRow fires before the deletion, the UserDeletedRow fires after.
If you set e.cancel = true, the row will not get deleted.
Ask your user with a simple messagebox.
Private Sub DataGridView1_UserDeleting
If Not MessageBox.Show("Are you sure?", "Deleting", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult
e.Cancel = True
End If
End Sub