blcamp
blcamp

Reputation: 119

Telerik GridViewSelectColumn - Map Checkbox To Boolean Property

(I've looked far and wide for a Q&A before asking, but please forgive if it's already around somewhere else and I missed it.)

I'm just trying to do something that seemingly should be simple... trying to map individual checkboxes in a telerik:GridViewSelectColumn in a telerik:RadGridView to a corresponding Boolean property of an entity mapped for each individual row.

<telerik:RadGridView x:Name="MyGridView" ItemsSource="{Binding MyGridViewItems, Mode=TwoWay}" SelectionMode="Extended" AutoGenerateColumns="False">    
    <telerik:RadGridView.Columns>
    <telerik:GridViewSelectColumn Name="MyCheckBoxColumn">
        <telerik:GridViewSelectColumn.CellTemplate>
        <DataTemplate>
            <CheckBox Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:GridViewDataControl}}, Path=DataContext.IncludeChangedCommand}" CommandParameter="{Binding}" IsChecked="{Binding MyBooleanProperty, Mode=TwoWay}" />
        </DataTemplate>
        </telerik:GridViewSelectColumn.CellTemplate>                                            
    </telerik:GridViewSelectColumn>

    .
    .
    .

    </telerik:RadGridView.Columns>
</telerik:RadGridView>

How do I map MyBooleanProperty to each individual checkbox?

Upvotes: 0

Views: 1509

Answers (2)

user10810200
user10810200

Reputation:

there is one solution as you have boolean variable MyBooleanProperty and you want to map it with every item of your list. so what you can do is make one boolean property in your wrapper class itself List<YourClass>

class would be like this or something

class Yourclass { bool ItemBool; }

now when you assign list just do linq and assign your ItemBool as per your condition

Upvotes: 0

mm8
mm8

Reputation: 169200

If you want to bind the CheckBox to a property of your data object, you should use a GridViewCheckBoxColumn or a GridViewDataColumn:

<telerik:GridViewDataColumn Name="MyCheckBoxColumn">
    <telerik:GridViewDataColumn.CellTemplate>
        <DataTemplate>
            <CheckBox Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:GridViewDataControl}}, Path=DataContext.IncludeChangedCommand}" 
                      CommandParameter="{Binding}"
                      IsChecked="{Binding MyBooleanProperty, Mode=TwoWay}" />
        </DataTemplate>
    </telerik:GridViewDataColumn.CellTemplate>
</telerik:GridViewDataColumn>

A GridViewSelectColumn does not bind to data. It simply allows you to select a given row.

Upvotes: 1

Related Questions