Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从ObservableCollection中删除当前行_C#_Wpf_Observablecollection - Fatal编程技术网

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)