C# 从绑定源限制的类型化数据集中删除行的最佳方法
C# 2008 SP1。
我正在从 datagridview 上当前选择的行中删除一行。
我正在使用类型化数据集,并且我的 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]);
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]);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您还可以使用 BindingSource 直接删除:
You could also delete directly using the BindingSource :
我认为您可以使用 DataRowView 的 Row 属性来缩短此时间。
I think you can shorten this using the Row property of the DataRowView.