Gern Blanston
Gern Blanston

Reputation: 42660

How to set up the datagrid control from the Xceed\Extended WPF Toolkit with checkbox column and binding

I'm trying to swap out a WPF datagrid to a xceed\Extended WPF Toolkit DataGridControl.

I need to react to the click event in a checkbox column ... to summarizing a number of other columns.

In the existing datagrid I have a checkbox column, that is bound to a Observable Collection and I call a method if any check box is checked\unchecked. The xaml I use for this, which works, is as such:

<DataGridTemplateColumn Width="40" Header="Inc">
<DataGridTemplateColumn.CellTemplate>
    <DataTemplate>
        <CheckBox
            IsChecked="{Binding Include ,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
            Checked="CheckBoxUpdated" Unchecked="CheckBoxUpdated" />
    </DataTemplate>
</DataGridTemplateColumn.CellTemplate>

For the xceed datagridcontrol I started with the simple syntax below, and the the initial binding seemed OK, but I don't have a click event to respond to:

<xcdg:Column   FieldName="Include" Title="Inc" />

Now I tried to do something similar to the original code using the xceed datagridcontrol, as such:

<xcdg:Column   FieldName="Include" Title="Inc" Width="*" >
<xcdg:Column.CellContentTemplate>
    <DataTemplate>
        <CheckBox IsChecked="{Binding Include ,UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Click="CheckBoxUpdated"/>
    </DataTemplate>
</xcdg:Column.CellContentTemplate>

But I don't think this is the correct syntax. It seems the binding is not working ... based on the initial values of the collection.

(note code behind sets this items source as such dg.ItemsSource = collectionView;)

Any ideas on how to setup a checkbox DataTemplate and the binding correctly?

Thanks

Upvotes: 4

Views: 8436

Answers (2)

xtds
xtds

Reputation: 2513

Your solution to your question wasn't working for me, what did work however:

Either

<xcdg:Column ...

if the type is boolean it will automaticly create a checkbox for it, you'll have to click 3 times though (column edit -> (un)check -> column out) which can be annoying.

OR

<xcdg:Column FieldName="ckb1" DisplayMemberBinding="{Binding Path=IsThisChecked,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" >
                    <xcdg:Column.CellContentTemplate>
                        <DataTemplate>
                            <CheckBox IsChecked="{xcdg:CellEditorBinding NotifyOnSourceUpdated=True}" HorizontalAlignment="Center" />
                        </DataTemplate>
                    </xcdg:Column.CellContentTemplate>
                </xcdg:Column>

Which doesn't need all the clicking

Upvotes: 2

Gern Blanston
Gern Blanston

Reputation: 42660

I just found a post at xceed forums that gave me the syntax I needed, that to set the FieldName=".", not FieldName="Include" . My guess is that having FieldName="Include" and the "{Binding Include ..." was confusing the binding.

<xcdg:Column   FieldName="." Title="Inc" Width="*" >
 <xcdg:Column.CellContentTemplate>
  <DataTemplate>
    <CheckBox IsChecked="{Binding Include ,UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Click="CheckBoxUpdated"/>
</DataTemplate>
</xcdg:Column.CellContentTemplate>

Upvotes: 6

Related Questions