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

SelectAll checkbox in GridView Header passing null

1 Answer 62 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Nexxas
Top achievements
Rank 1
Nexxas asked on 13 Feb 2014, 05:50 PM
I am using an MVVM pattern for binding my UI. I am using ICommand's to attach the handlers. I created a "Select All" checkbox in the Header of a GridViewDataColumn, but every time I pass the commandParameter of the SelectAll checkbox itself, it comes up null. 

However, it worked perfectly if I take the EXACT SAME checkbox and move it EITHER completely outside of the RadGridView, or even into a CellTemplate. It appears the binding is occurring before the Header has been created. Or am I just creating a "Select All" completely wrong?

XAML:
<UserControl>
    <UserControl.Resources>
        <c:InfoBaseViewModel x:Key="InfoBaseViewModel2"/>
    </UserControl.Resources>
    <DockPanel Name="InfoDockPanel" DataContext="{StaticResource InfoBaseViewModel2}">
        <telerik:RadGridView x:Name="grdInfo" AutoGenerateColumns="False" IsReadOnly="True" ItemsSource="{Binding Path=InfoList}" ShowGroupPanel="False">
  
                <telerik:GridViewDataColumn>
                    <telerik:GridViewDataColumn.Header>
  
                        <CheckBox Name="chkAll" CommandParameter="{Binding ElementName=chkAll}" Command="{Binding AllCheckedCommand,Source={StaticResource InfoBaseViewModel2}}" ></CheckBox>
  
                    </telerik:GridViewDataColumn.Header>
                    <telerik:GridViewDataColumn.CellTemplate>
                        <DataTemplate>                          
                            <CheckBox IsChecked="{Binding Path=IsItemSelected, Mode=TwoWay}"></CheckBox>
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellTemplate>
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding FullName}" Header="{Binding Path=ApplicationStrings.FullNameLabel, Source={StaticResource ResourceWrapper}}"></telerik:GridViewDataColumn>
                </telerik:GridViewDataColumn>
  
        </telerik:RadGridView>
    </DockPanel>
</UserControl>

ViewModel command handler:
public ICommand AllCheckedCommand
{
    get { return _allItemsChecked ?? (_allItemsChecked = new RelayCommand(AllCheckedHandler, null)); }
}
 
public void AllCheckedHandler(object sender)
{
    // Always gets to here...
    var chkAll = sender as System.Windows.Controls.CheckBox;
     
    if (chkAll == null)
    {
        // ...but always fails
        Logger.Error("Error binding the 'Select All' checkbox.");
    }
    else
    {
        foreach (var item in InfoList)
        {
            item.IsItemSelected = (bool)chkAll.IsChecked;
        }
        base.OnPropertyChanged("InfoList");
    }
}

1 Answer, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 18 Feb 2014, 09:16 AM
Hello,

I believe that you have binding expressions in the output. If so, you can check this troubleshooting article for a reference.

Please give it a try and let me know how it works for you.


Regards,
Yoan
Telerik
Tags
GridView
Asked by
Nexxas
Top achievements
Rank 1
Answers by
Yoan
Telerik team
Share this question
or