This is a migrated thread and some comments may be shown as answers.

Problem with recreating columns when a filter is applied

5 Answers 76 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Björn
Top achievements
Rank 1
Björn asked on 28 Jun 2012, 01:39 PM

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()...

5 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 28 Jun 2012, 01:52 PM
Hello,

 I have executed the code snippet you provided but I did not get any exception no matter how many times I clicked on the button. Have you tried with the latest assmblies?

Kind regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Björn
Top achievements
Rank 1
answered on 28 Jun 2012, 02:00 PM
Hi!
Thanks for a very quick response!

In my post i only referred to the FilteringMode setting, but it was not included in the sample.
If you add the following code to the windo constructor I think you will get the exception:

radGridView1.FilteringMode = Telerik.Windows.Controls.GridView.FilteringMode.FilterRow;

Best regards,
Björn
0
Rossen Hristov
Telerik team
answered on 02 Jul 2012, 10:43 AM
Hi,

We have fixed this issue. The fix will make it with out next Latest Internal Build. Let us know if you encounter any problems after upgrading to it.

All the best,
Ross
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Björn
Top achievements
Rank 1
answered on 06 Jul 2012, 02:08 PM

Thank you for the swift fix of the gridview filter problem!
I am now using RadControls_for_WPF_2012_2_0703_DEV_hotfix and the filter seems to work.

However i noted a change in the behaviour of the Docking framework in this build compared to the 2012-2 release.

Calling  :
pane.RemoveFromParent(); 
e.Handled = true
in RadDocking_PreviewClose event causes a null exception.

This is not a problem for me because I changed the code so that e.Handled is only used when canceling the close and removed the call to pane.RemoveFromParent. I just wanted to make you aware of this change in behaviour.

Sample below.
Best regards
Björn

MainWindow.xaml

<Window x:Class="DockingProblem.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
        Title="MainWindow" Height="350" Width="525">

    <telerik:RadDocking PreviewClose="RadDocking_PreviewClose">
       
        <telerik:RadSplitContainer InitialPosition="DockedTop" Height="50">
            <telerik:RadPaneGroup>
                <telerik:RadPane>
                    <StackPanel>
                        <Button Click="Button_Click">Create pane</Button>
                    </StackPanel>
                </telerik:RadPane>
            </telerik:RadPaneGroup>
        </telerik:RadSplitContainer>

        <telerik:RadDocking.DocumentHost>
            <telerik:RadSplitContainer>
                <telerik:RadPaneGroup Name="paneGroup"></telerik:RadPaneGroup>
            </telerik:RadSplitContainer>
        </telerik:RadDocking.DocumentHost>

    </telerik:RadDocking>

MainWindow.xaml.cs:

using System;
using System.Linq;
using System.Windows;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.Docking;

namespace DockingProblem
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();                     
        }
      
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            RadPane pane = new RadPane();
            pane.Title = "A Pane " + DateTime.Now.ToLongTimeString();
            paneGroup.Items.Add(pane);
        }

        private void RadDocking_PreviewClose(object sender, StateChangeEventArgs e)
        {           
            RadPane pane = e.Panes.First();

            if (pane != null)
            {
                pane.RemoveFromParent();
                e.Handled = true;
            }
        }
    }
}

0
Konstantina
Telerik team
answered on 13 Jul 2012, 08:10 AM
Hello,

This exception is caused because the Docking control is also trying to close the pane, which doesn't exist anymore. To work-around it you have to handle the PreviewClose event after removing the pane, how you mentioned.

Kind regards,
Konstantina
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Tags
GridView
Asked by
Björn
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Björn
Top achievements
Rank 1
Rossen Hristov
Telerik team
Konstantina
Telerik team
Share this question
or