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

标签 c# datagridview dataset bindingsource

C# 2008 SP1。

我正在从当前在数据 GridView 中选择的行中删除一行。

我使用的是类型化数据集,我的数据 GridView 绑定(bind)到绑定(bind)源。

然而,我认为我的技术不是最好的,即使它有效。

非常感谢任何建议,

 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]);

最佳答案

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

bsAddressBook.RemoveCurrent();

关于C# 从绑定(bind)源限定的类型化数据集中删除行的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/867349/

相关文章:

c#-4.0 - 是否可以在 C# 中仅使用数据集来使用 NHibernate

javascript - 如何将 D3 数据插值/动画函数应用于动态变化的饼图

c# - 获取 PDF 文件中的超链接列表

c# - C# 属性是如何工作的?

c# - C#调用BeginInvoke/Invoke时如何获取返回值

c# - 为什么 Columns 在调用 DataGridView.Columns.Clear() 后不保持隐藏状态?

c# - 在 FullRowSelect 模式下将 datagridview 单元格内容复制到剪贴板

c# - ASP.Net MVC 4 PUT 请求响应 409 - 冲突

c# - 清除所有值并在 DataGridView 中再次加载它(刷新)

c# - 使用输出更新 (@MyTableVar),在 C# 中失败,在 SQL Server 中工作正常