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

problem with column;s Is visible proprty in combination with a coun function

0 Answers 43 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Vinod
Top achievements
Rank 1
Vinod asked on 26 Nov 2011, 09:18 AM
i am displaying two columns in the grid view and their visibilities (i.e. IsVisible Property) are controlled by corresponding check boxes. Also i have applied a count function in first column. so first time when i run the application it showing all the columns successfully but if i do Isvisible property of first column to false and then load the gridview with new data it shows an error in the handler of the INotifyPropertyCanhged Interface.

And the error is: "Object reference not set to an instance of an object."


please help me out.,....
public partial class PlaybackView : UserControl, INotifyPropertyChanged
    {
 
        int _count = 0;
 
        public PlaybackView()
        {
            InitializeComponent();
        }
 
 
        #region Properties
 
        public DataTable PlaybackTable
        {
            get { return (DataTable)GetValue(PlaybackTableProperty); }
            set
            {
                SetValue(PlaybackTableProperty, value);
            }
 
        }
 
        // Using a DependencyProperty as the backing store for DataTable.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty PlaybackTableProperty = DependencyProperty.Register("PlaybackTable", typeof(DataTable), typeof(PlaybackView));
 
        //private static void OnPresentableTableChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        //{
        //    PlaybackView playbackView = d as PlaybackView;
 
        //    if (playbackView != null)
        //    {
 
        //        playbackView.PlaybackLogView = new ListCollectionView(playbackView.PlaybackTable.DefaultView);
        //    }
        //}
 
 
        public List<string> GroupBy
        {
            get { return (List<string>)GetValue(GroupByTextProperty); }
            set
            {
                SetValue(GroupByTextProperty, value);
 
            }
        }
 
        public static readonly DependencyProperty GroupByTextProperty = DependencyProperty.Register("GroupBy", typeof(List<string>), typeof(PlaybackView), new UIPropertyMetadata(null, OnGroupByPropertyChanged));
 
        private static void OnGroupByPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            //PlaybackView playbackView = d as PlaybackView;
 
            //if (playbackView != null)
            //{
            //    playbackView.PlaybackLogView.GroupDescriptions.Add(new PropertyGroupDescription(playbackView.GroupBy));
                
            //}
        }
 
        #endregion
 
 
 
        #region INotifyPropertyChanged Members
 
        public event PropertyChangedEventHandler PropertyChanged;
 
        protected void OnPropertyChanged(string name)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(name));
            }
        }
 
        #endregion
 
        private void telrikDataGrid_DataLoading(object sender, Telerik.Windows.Controls.GridView.GridViewDataLoadingEventArgs e)
        {
            if (GroupBy.Count > 0)
            {
                if (_count > 0)
                {
                    this.telrikDataGrid.GroupDescriptors.Clear();
                }
 
                ColumnGroupDescriptor descriptor = new ColumnGroupDescriptor();
                descriptor.Column = this.telrikDataGrid.Columns[GroupBy[0]];
                this.telrikDataGrid.GroupDescriptors.Add(descriptor);
                ++_count;
 
            }
 
        }
 
    }
 
 
-------------------------------------------XAMl Code----------------------------------------------
 
 <Grid>
 
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
 
        <Button  Content="Load Data" HorizontalAlignment="Right" Click="Button_Click" />
        <CheckBox x:Name="_check" Grid.Row="1" Content="Visibility" IsChecked="True"/>
 
        <telerik:RadGridView  Grid.Row="2" x:Name="_telerikGrid" ShowColumnFooters="True"  AutoGenerateColumns="False" ItemsSource="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=Table}">
 
            <telerik:RadGridView.Columns>
 
 
                <telerik:GridViewDataColumn Header="PresentationName" DataMemberBinding="{Binding PresentationName}">
                </telerik:GridViewDataColumn>
 
                <telerik:GridViewDataColumn Header="LogLevel" DataMemberBinding="{Binding LogLevel}" IsVisible="{Binding ElementName=_check, Path=IsChecked}">
                    <telerik:GridViewDataColumn.AggregateFunctions>
                        <telerik:CountFunction Caption="Total Rows"/>
                    </telerik:GridViewDataColumn.AggregateFunctions>
                </telerik:GridViewDataColumn>
 
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>
 
 
    </Grid>

No answers yet. Maybe you can help?

Tags
GridView
Asked by
Vinod
Top achievements
Rank 1
Share this question
or