Abhilash J A

Abhilash J A

  • 538
  • 2.4k
  • 596.4k

WPF - Operation is not valid while ItemsSource is in use.

Oct 31 2016 10:25 AM
On wpf combobox DropdownClosed, I want to bind ListView.
 
  1. private void cmbAction_DropDownClosed(object serder, EventArgs e)  
  2.       {  
  3.           int UserID = 26;  
  4.           string Actions = cmbAction.SelectedValue.ToString();  
  5.           var data = service.PostLogDetails(UserID);  
  6.           if (Actions == "Login")  
  7.           {  
  8.               var listItems = (from A in data orderby A.FirstName select new { Action = "Login", AccessDate = A.LogInTime });  
  9.               listView1.Items.Clear();  
  10.               listView1.ItemsSource = listItems;  
  11.           }  
  12.           else if (Actions == "Logout")  
  13.           {  
  14.               var listItems = (from A in data orderby A.FirstName select new { Action = "LogOut", AccessDate = A.LogOutTime });  
  15.               listView1.Items.Clear();  
  16.               listView1.ItemsSource = listItems;  
  17.           }  
  18.       }  
After using this code, showing error.
"Operation is not valid while ItemsSource is in use. Access and modify elements with ItemsControl.ItemsSource instead."
How can I solve this?
 

Answers (2)