On wpf combobox DropdownClosed, I want to bind ListView.
- private void cmbAction_DropDownClosed(object serder, EventArgs e)
- {
- int UserID = 26;
- string Actions = cmbAction.SelectedValue.ToString();
- var data = service.PostLogDetails(UserID);
- if (Actions == "Login")
- {
- var listItems = (from A in data orderby A.FirstName select new { Action = "Login", AccessDate = A.LogInTime });
- listView1.Items.Clear();
- listView1.ItemsSource = listItems;
- }
- else if (Actions == "Logout")
- {
- var listItems = (from A in data orderby A.FirstName select new { Action = "LogOut", AccessDate = A.LogOutTime });
- listView1.Items.Clear();
- listView1.ItemsSource = listItems;
- }
- }
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?