C# Clear all items in ListView

前端 未结 12 1872
我在风中等你
我在风中等你 2020-12-03 13:39

I try to clear my listview but the clear method doesn\'t work:

myListView.Items.Clear();

This doen\'t work. When i put a breakpoint at this

相关标签:
12条回答
  • 2020-12-03 13:51

    How about

    DataSource = null;
    DataBind();
    
    0 讨论(0)
  • 2020-12-03 13:51

    This is bit late, but this works for me at least using UWP

    myListView.ItemsSource = null;
    
    0 讨论(0)
  • 2020-12-03 14:00

    The Problem is arising because you are trying to clear the entire list box. Just use listView1.Items.Clear();

    0 讨论(0)
  • 2020-12-03 14:06
    listView.Items.Clear()
    listView.Refresh() 
    

    /e Updating due to lack of explanation. Often times, Clear() isn't suffice in the event of immediate events / methods following. It's best to update the view with Refresh() following a Clear() for an instant reflection of the listView clearing. This, anyhow had solved my related issues.

    0 讨论(0)
  • 2020-12-03 14:10

    Try with this:

    myListView.ItemsSource = new List< DictionaryEntry >();
    
    0 讨论(0)
  • 2020-12-03 14:11

    I did a search on this and I am using WPF c#. Just in case you got here too looking for a WPF solution use the following:

    yourlistview.ItemsSource = null;

    0 讨论(0)
提交回复
热议问题