Hi,
Does anyone know how to solve the following problem ?
I have a grid which datasource is filled based on a stored procedure. In the xaml I have added the styles for the checkbox for each record and for the header.
The problem is that if I click the header checkbox, this gets selected but all the records remain unchecked. I have no idea how I can change this such that all the records are checked/unchecked too. Probably there is a simple trick, can someone help me ?
C# code:
xamMainGrid.DataSource = MyLinqConn.loadMainGridOverview(strcomboValuationDate, decThreshold, strActiveFlag);
List<pAppDealPriceOverviewResult> loadMainGridOverview
XaML code:
<!-- 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" IsChecked="{Binding Path=DataItem.IsChecked, Mode=TwoWay}" VerticalAlignment="Center" Checked="fRecordChecked" Unchecked="fRecordUnChecked" /> </ControlTemplate> </Setter.Value> </Setter> </Style> <!-- This Style puts a CheckBox into the header area above the record selectors. --> <Style TargetType="{x:Type igDP:HeaderPrefixArea}" BasedOn="{x:Null}"> <Setter Property="Visibility" Value="Visible" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igDP:HeaderPrefixArea}"> <CheckBox HorizontalAlignment="Center" VerticalAlignment="Center" IsChecked="{Binding Path=DataPresenter.DataContext.AllMembersAreChecked, Mode=TwoWay}" Checked="fAddAllRecordsToCheckList" Unchecked="fRemoveAllRecordsFromCheckList" /> </ControlTemplate> </Setter.Value> </Setter>
Hello,
You would have to provide manual code for checking / unchecking all of the records in the Checked/Unchecked events of the CheckBox. I can see, that you have bound the value of the CheckBox to the corresponding DataItem's IsChecked property. In the Checked/UnChecked events, you need to iterate thorough the record that you need to check or uncheck and set their DataItem.IsChecked properties to true or false respectively.
thanks for your feedback. But can you tell me as well how I can change the dataitem.ischecked to true or false. More specifically, can you provide me an example of how to change a datarecord dataitem.IsChecked property when iterate through the records ?
Thank you in advance
I haven't found yet the solution for this. I can iterate through the records but I fail to change the data item is checked property to true or false programmically. As you can see in my previous posts, the checkbox for each record is bounded to the dataitem "IsChecked" which is however not part of my datasource initially.
Anyone an idea how I can change programmically the value of each record's checkbox ?
As I'm interested in buying the full version of the infragistics wpf tools, this functionality is really necessary for my development and will have an impact on my decision...
Hi cowboyhenk,
If the IsChecked property isn't a part of your initial dataset, you have to include it into the dataset you're binding to the XamDataGrid. One option is to create a descendant class of the data item class you're binding, adding to it only the IsChecked property (which has to also implement INotifyPropertyChanged and to raise the event with the name of the IsChecked property), creating a List or an ObservableCollection of this class, and adding an instance of the extended data item class for each instance of the initial data item class.
That is, if you are binding:
public Row : INotifyPropertyChanged
{
private int _count;
public int Count { get { return _count;} set { _count = value; RaisePropertyChanged("Count"); }}
...(implementation of the INotifyPropertyChanged interface)
}
you will declare a new class:
public RowEx : Row, INotifyPropertyChanged
private int _isChecked;
public int IsChecked { get { return _isChecked;} set { _count = value; RaisePropertyChanged("IsChecked"); }}
You can then add code to set the IsChecked property of all records appropriately in the event handlers of the Checked and Unchecked events of the checkbox used for all-record selection as shown below:
private void allRecordSelector_Checked(object sender, RoutedEventArgs e) { foreach (object o in xamDataGrid1.DataSource) { RowEx r = o as RowEx; if (r != null) { r.IsChecked = true; } } } private void allRecordSelector_Unchecked(object sender, RoutedEventArgs e) { foreach (object o in xamDataGrid1.DataSource) { RowEx r = o as RowEx; if (r != null) r.IsChecked = false; } }
Best,Kiril