I got exception : Operation is not valid while ItemsSource is in use. Access and modify elements with ItemsControl.ItemsSource instead.
A:
You must add the items to your source-collection that is set to ItemsSource
. After you have set the ItemsSource
-property to a value, its no more possible to use the Items
-property (besides you set ItemsSource
newly to null). Items
and ItemsSource
exclude each other.
If you use ItemsSource
, your source-collection must implement INotifyCollectionChanged
so that it will inform the ListView about changes. If not, added items to it will not change the ListView. E.g. if you use List<T>
as items-source, changes will not be forwarded.
There exist classes that do that for you such as ObservableCollection<T>
.
HCL
2010-09-08 06:51:06
I used Observable collection but it display same error
mandarBadve
2010-09-08 08:21:36
Do you use yourListView.Items.Add(newItem) or myObservableCollection.Add(newItem)
HCL
2010-09-08 08:25:20
Thank you Now Its run comfortably
mandarBadve
2010-09-08 10:37:15
If it helped you, please mark the answer as accepted by checking the checkmark under the Points-display.
HCL
2010-09-08 11:01:57