C#从绑定源绑定的类型化数据集中删除行的最佳方法

ant*_*009 2 c# datagridview dataset bindingsource

C#2008 SP1.

我正在从datagridview上当前选中的行中删除一行.

我正在使用Typed数据集,我的datagridview被绑定到绑定源.

但是,我认为我的技术并不是最好的,即使它有效.

非常感谢任何建议,

 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]);
Run Code Online (Sandbox Code Playgroud)

Tho*_*que 5

您也可以使用BindingSource直接删除:

bsAddressBook.RemoveCurrent();
Run Code Online (Sandbox Code Playgroud)