views:

2173

answers:

1

Hello,

C# 2008 SP1.

I am deleting a row from a row that is currently selected on a datagridview.

I am using a Typed dataset and my datagridview is bounded to a binding source.

However, I think my technique is not the best, even though it works.

Many thanks for any advice,

 DataRow[] drDelete;
            // Get the value of the PK from the currently selected row
            DataRowView drv = (DataRowView)bsAddressBook.Current;
            int index = Convert.ToInt16(drv[0]);

            // Find the actual data row from the primary key and delete the row
            drDelete = dsCATDialer.AddressBook.Select(string.Format("ID = '{0}'", index));
            dsCATDialer.AddressBook.Rows.Remove(drDelete[0]);
+2  A: 

You could also delete directly using the BindingSource :

bsAddressBook.RemoveCurrent();
Thomas Levesque