如何使用行標記ID從列表視圖中刪除行?從列表視圖中刪除一行TAG ID
-1
A
回答
1
您可以撥打ListViewItem
上的ListViewItem.Remove
方法您想要刪除。
此方法與ListView控件中包含該項目的ListView.ListViewItemCollection的Remove方法在功能上類似。您可以使用Remove方法從其ListView控件中刪除項目。如果要將項目移動到其他ListView控件,或者需要根據用戶的請求刪除項目以從應用程序中刪除項目,則此功能可能很有用。
例如,你可以通過所有的ListViewItems
的週期在ListView
,看Tag
,並Remove
要刪除的項目:
// Create the ListView and ListViewItem.
ListView myList = new ListView();
ListViewItem myItem = new ListViewItem { Tag = "MyTag", Text = "My ListViewItem" };
myList.Items.Add(item);
// Look for the ListViewItem with a Tag of "MyTag" and remove it.
foreach (ListViewItem item in myList.Items) {
if (String.CompareOrdinal(item.Tag as string, "MyTag") == 0) {
i.Remove();
break;
}
}
這個例子除去第一匹配後退出項目。如果需要刪除多個匹配的ListViewItems
,則需要將這些匹配集合起來,然後再刪除它們。
0
將來您應該向社區展示您爲問題付出的努力量。你可以告訴我們你的嘗試,並給我們一些例子。但是,下面是一些應該幫助解答您的問題的代碼。
int id = 0;
foreach (ListViewItem item in listView1.Items)
{
if((int)item.Tag == id)
{
item.Remove();
break;
}
}
注意:這裏假定標記是一個整數。如果情況並非總是如此,那麼您應該添加代碼以防止錯誤。
1
這是我做的一個快速功能。它使用linq。 myTag
可以是任何對象。
string myTag = "aaa";
List<ListViewItem> lst = listView1.Items.Cast<ListViewItem>().Where(i => i.Tag == myTag).ToList();
if (lst.Count != 0)
{
listView1.Items.Remove(lst.First());
}
相關問題
- 1. 從表格視圖中刪除一行
- 2. 從表格視圖中刪除一行
- 3. Android - 從水平可縮放列表視圖中刪除一行
- 4. Android從列表視圖中刪除
- 5. 從列表視圖中刪除項目
- 6. xcode - 從表格視圖刪除一行
- 7. 從列表視圖及其文本文件中刪除一行
- 8. 從列表視圖中刪除行根據列的值
- 9. 從輪廓視圖中刪除一行
- 10. 從列表視圖中刪除數據
- 11. 從列表視圖中刪除項目
- 12. 從列表視圖中刪除項目
- 13. C#從列表視圖中從列表視圖中刪除項目
- 14. 從表格視圖中刪除行
- 15. 刪除從表中的特定行與列表視圖
- 16. Android的sqlite從列表視圖刪除
- 17. 從視圖刪除行從基表刪除行 - MYsql?
- 18. 動態從列表視圖中刪除一個佈局
- 19. 使用列表視圖刪除sqlite行
- 20. Android的 - 刪除一行SQL和列表視圖中的項目
- 21. 從DataRow列表中刪除一行
- 22. 如何從Windows中刪除視圖 - >顯示視圖列表?
- 23. 從表中刪除一行
- 24. 試圖從表格中刪除一行
- 25. 刪除一個列表視圖條目
- 26. 如何在列表視圖中從sqlite中刪除行Android
- 27. 如何從列表視圖中刪除當前行
- 28. 從列表視圖中刪除最後一個元素
- 29. 如何從Android的列表視圖中刪除行項目?
- 30. 從列表視圖中刪除特定的行?