I have a datagrid that I load dynamically. I have added check boxes to the record selector area of the grid. I want to be able to check the records in the grid based on whether the date of the record is greater than a certain value. I am trying to set the check state in the InitializeRecord routine. I am coding in VB. How do I reference the checkbox state?
Thanks in advance.
Chris
I'm also having the similar issue and even after making the Two binding it doesn't work in my case.
<DataTemplate><StackPanel Orientation="Vertical" HorizontalAlignment="Center"><TextBlock x:Name="lblSelectHeader" Text="Select All" Margin="5,0,0,0"></TextBlock> <CheckBox x:Name="chkSelectAll" IsChecked="{Binding IsSelected, Mode=TwoWay}" HorizontalAlignment="Center" Click="chkSelectAll_Click" ></CheckBox> </StackPanel> </DataTemplate>
DO u have any other alternate way to fix this issue.
I appreciate quick help
Hi cowboyhenk,
I've achieved the desired behavior by maknig the Binding in the IsChecked property a TwoWay binding. This allows you to update the value of the bound object using the checkbox in the record selector. This value is then displayed in the checkbox of the same row, once it is brought back into view.
If you set the value of the CheckBox programmatically rather than using a two-way binding, it will be lost once the user scrolls, because the XamDataGrid reuses the same visual elements to display the currently visible bound items (which change everytime you scroll).
Please find your style code modified below, with the change marked in bold. I have also removed references to event handlers for the Checked and Unchecked events.
<!-- This Style puts a CheckBox into the record selectors. --> <Style BasedOn="{x:Null}" TargetType="{x:Type igDP:RecordSelector}"> <Setter Property="Control.Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igDP:RecordSelector}"> <CheckBox HorizontalAlignment="Center" VerticalAlignment="Center" IsChecked="{Binding Path=DataItem.IsChecked, Mode=TwoWay}" /> </ControlTemplate> </Setter.Value> </Setter> </Style>
Best,
Kiril
Hi, I have exactly the same problem, can you be more precisely Alex ?
BruCru, do you already have a solution for this ?
I use the following style:
<!-- This Style puts a CheckBox into the record selectors. --> <Style BasedOn="{x:Null}" TargetType="{x:Type igDP:RecordSelector}"> <Setter Property="Control.Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igDP:RecordSelector}"> <CheckBox HorizontalAlignment="Center" VerticalAlignment="Center" IsChecked="{Binding Path=DataItem.IsChecked, Mode=OneWay}" Checked="fMDEReqAssetChecked" Unchecked="fMDEReqAssetUnChecked" /> </ControlTemplate> </Setter.Value> </Setter> </Style>
Thank you in advance
Hello Chris,
It is best to bind twoway the Checkbox to some property of the record - for example the Tag property and control its states through the Record object. As the XamDataGrid uses virutalization by default, if you set the value of the CheckBox itself, this value will be lost when you scroll records in/out of view.