Can not Clear ListBox.Items

3 posts, 0 answers
  1. Mike
    Mike avatar
    17 posts
    Member since:
    Oct 2010

    Posted 24 Apr 2013 Link to this post

    Hello,

    I try to delete / clear the Items of a Listbox with
    Me.datarowExtList.Clear()

    But i get an NullReferenceException, since there are some Elements in the Listbox

    I bind a ObservableCollection to the Itemsource Property of the LIstbox:
    ItemsSource="{Binding datarowExtList}" SelectionMode="Single" DisplayMemberPath="DocDescription"

    Private _datarowExtList As ObservableCollection(Of DataRowExt) = New ObservableCollection(Of DataRowExt)
        Public Property datarowExtList() As ObservableCollection(Of DataRowExt)
            Get
                Return _datarowExtList
            End Get
            Set(ByVal value As ObservableCollection(Of DataRowExt))
                _datarowExtList = value
                NotifyPropertyChanged("datarowExtList")
            End Set
        End Property

    so - as i said, if there are no items in the Listbox shown up (ListBox.Items.Count = 0) i can do the Clear of the ObservableCollection.
    But if there are any Items in the Listbox (just visual, neither in ListBox.Items or neither in my ObservableCollection) i get the NullReferenceException, on the Line of the ObservableCollection.CLear()

    Whats wrong with the Listbox? what am i missing or doing wrong?

    thanks for any advice

    regards
    Mike
  2. Vladi
    Admin
    Vladi avatar
    744 posts

    Posted 25 Apr 2013 Link to this post

    Hi,

    As we see you have posted a support thread with ID: 686258 about the same issue could we continue the discussion there?

    I will post our response from that thread in order for it to be available for the community:

    We tried to reproduce the issue but to no avail.

    I created and attached a sample project for you that shows there isn't any unexpected behavior when clearing the collection from the ViewModel.

    All the best,
    Vladi
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Mike
    Mike avatar
    17 posts
    Member since:
    Oct 2010

    Posted 26 Apr 2013 Link to this post

    Hi,

    I could solve my Problem - so you can also close my ticket (sorry for that)

    the Problem was, that i accessed the ListBox, during SelectionChanged Event, and in some cases the ListBox was Null.
    So i just had to handle that...


    thanks & regards
    Mike
Back to Top