C# 从ObservableCollection中删除当前行
我有一个列表视图,它与C# 从ObservableCollection中删除当前行,c#,wpf,observablecollection,C#,Wpf,Observablecollection,我有一个列表视图,它与observetecollection绑定。我想通过单击按钮从observedcollection中删除列表视图中的选定行 如何获得选定的行位置?我的收藏不包含ID 您可以看到我正在使用的代码。假设您有常规类(不重写Equals),那么您可以简单地删除它: myCollection.Remove(Listbox1.Selecteditem) 使用ListView: myCollection.RemoveAt(Listbox1.SelectedIndex); 提示:他将
observetecollection
绑定。我想通过单击按钮从observedcollection
中删除列表视图中的选定行
如何获得选定的行位置?我的收藏不包含ID
您可以看到我正在使用的代码。假设您有常规类(不重写Equals),那么您可以简单地删除它:
myCollection.Remove(Listbox1.Selecteditem)
使用ListView:
myCollection.RemoveAt(Listbox1.SelectedIndex);
提示:他将如何使用它?或者在我的情况下,我想做同样的事情;我将如何处理
SelectedIndex
属性?OP询问所选行位置,我认为他指的是所选项目的索引,即SelectedIndex。我对你的情况一无所知,如果不同的话,可以作为新问题发布。我的意思是字面意思<代码>myCollection.Remove(列表框1.SelectedIndex)代码>?IList有一个void RemoveAt(int index)方法,ObservableCollection实现该方法。因此myCollection.RemoveAt(Listbox1.SelectedIndex)代码>?