I am creating a form where the columns will be created and recreated dynamically.
The user selects a predefined view with sorting, filtering and grouping.
He then enters filter criterias and retrievs data from a service.
The problem occurs when the user selects another view which may contain other columns.
At that point the column collection is cleared and the ItemsSource is set to null but this
seems to cause exceptions in the filtering mechanism. I can't figure out how to get around this problem.
I am using the new FilterRow but I think the problem also affects the popup mode.
The code below illustrates the problem when theButton is pressed TWICE.
private void theButton_Click(object sender, RoutedEventArgs e)
{
radGridView1.Columns.Clear();
// Create grid columns
radGridView1.Columns.Add(new GridViewDataColumn() { Name = "A", DataType = typeof(string),
DataMemberBinding = new Binding("A") });
radGridView1.Columns.Add(new GridViewDataColumn() { Name = "B", DataType = typeof(string),
DataMemberBinding = new Binding("B") });
// Create dummy data
DataTable dataTable = new DataTable();
dataTable.Columns.Add("A", typeof(string));
dataTable.Columns.Add("B", typeof(string));
dataTable.Rows.Add(new object[] { "0A", "0B" });
dataTable.Rows.Add(new object[] { "1A", "1B" });
radGridView1.ItemsSource = dataTable;
// Filter data
radGridView1.Columns["A"].ColumnFilterDescriptor.FieldFilter.Filter1.Value = "0";
radGridView1.Columns["A"].ColumnFilterDescriptor.FieldFilter.Filter1.Operator =
Telerik.Windows.Data.FilterOperator.Contains;
}
The second time the button is pressed the following exception occurs:
System.NullReferenceException was unhandled
Message=Object reference not set to an instance of an object.
Source=Telerik.Windows.Controls.GridView
StackTrace:
at Telerik.Windows.Controls.GridView.FieldFilterControlViewModel.RefreshEditorIsEnabled()...