TAN WhoAMI

TAN WhoAMI

  • NA
  • 291
  • 0

Clear WPF ListBox which is bind to a list

Jun 10 2012 10:24 PM
I am trying to clear and populate the WPF ListBox with new values at each click of the button, but apparently, I cannot clear it because it is bind to some list.

error message is as below when the commented line is there:
Operation is not valid while ItemsSource is in use. Access and modify elements with ItemsControl.ItemsSource instead.

My source code is as attached.

Appreciate any useful help.

================================

I have found the answer. Replace the commented line with

lucky_listBox.ItemsSource =

null;

Attachment: code.zip

Answers (1)