This is a migrated thread and some comments may be shown as answers.

Can not Clear ListBox.Items

2 Answers 164 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 24 Apr 2013, 12:19 PM
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 Answers, 1 is accepted

Sort by
0
Vladi
Telerik team
answered on 25 Apr 2013, 08:14 AM
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.

0
Mike
Top achievements
Rank 1
answered on 26 Apr 2013, 08:12 AM
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
Tags
ListBox
Asked by
Mike
Top achievements
Rank 1
Answers by
Vladi
Telerik team
Mike
Top achievements
Rank 1
Share this question
or