C#WPF:DataGrid,删除所选行
我创建了一个链接到数据库(表)的DataGrid。我的问题是如何从DataGrid中删除选定的行(使用btn_单击),以及如何从数据库(表)中删除相同的数据C#WPF:DataGrid,删除所选行,c#,wpf,C#,Wpf,我创建了一个链接到数据库(表)的DataGrid。我的问题是如何从DataGrid中删除选定的行(使用btn_单击),以及如何从数据库(表)中删除相同的数据 提前谢谢 您可以使用SelectedItem属性访问DataGrid的当前选定项 然后可以调用Remove方法从DataGrid var selectedItem = myDataGrid.SelectedItem; if (selectedItem != null) { myDataGrid.Items.Remove(selecte
提前谢谢 您可以使用
SelectedItem
属性访问DataGrid
的当前选定项
然后可以调用Remove
方法从DataGrid
var selectedItem = myDataGrid.SelectedItem;
if (selectedItem != null)
{
myDataGrid.Items.Remove(selectedItem);
}
在第一行之后,您需要从项目中提取信息(例如某些Id),以便将其删除到数据库中。
通常将SelectedItem
投射到用于绑定到网格的对象
另见答复