Hy.
I have a question about the RecordSelector's header for the XamDataGrid.
I have a XamDataGrid for which I have changed the template for the RecordSelector to contain a checkbox for selecting the records. This checkbox it's bounded to a property of the objects displayed inside the grid. Everything work's fine. But I would like to change the header of the RecordSelector to contain also a checkbox, with the select all functionality. I have no idea how to reference the header of the RecordSelector. Is there a way to do this?
<Style x:Key="CheckBoxSelector" TargetType="{x:Type dataPresenter:RecordSelector}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type dataPresenter:RecordSelector}">
<CheckBox IsChecked="{Binding Path=DataItem.Selected, Mode=TwoWay}" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Thanks very much
Nico
Nico Oprescu said:But I would like to change the header of the RecordSelector to contain also a checkbox, with the select all functionality.
Hi Nico,
I don't understand what this means. Please clarify what it means to have "select all functionality" exposed in the header of a RecordSelector. What is the "all" that is being selected? All of the child records? All of the checkboxes in the record? What is the problem that you're facing when trying to implement this?
Thanks,
Josh
Hy Josh.
Thanks very much for the answer.
I changed the style of the RecordSelector to be a checkbox, so when you select a row from the grid, this will be checked or uncheked. But on the header of the RecordSelector coulmn I would like to have also a checkbox and when this is checked, to check all the checkboxes of the RecordSelector for all the records inside the grid (somethig like select all records from the grid). But I don't know how the header of the RecordSelector column it's called.......LabelPresenterRecordSelector?
If you have any other questions please let me know. Thanks a lot.
I moled the XamDataGrid's visual tree and discovered that the field labels are all contained within a Grid panel. The "header" of the row selectors "column" is really just some empty space in that Grid. So, with a little XAML magic, and the use of the endlessly useful Infragistics.Windows.Utilities class, I found a way to put a CheckBox in that empty area. Here's what I did...
<igDP:XamDataGrid DataSource="{Binding}"> <igDP:XamDataGrid.Resources> <Style TargetType="{x:Type igDP:RecordSelector}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igDP:RecordSelector}"> <CheckBox IsChecked="{Binding Path=DataItem.Selected, Mode=TwoWay}" VerticalAlignment="Center" HorizontalAlignment="Center" /> </ControlTemplate> </Setter.Value> </Setter> </Style> </igDP:XamDataGrid.Resources> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> <igDP:FieldLayout.Fields> <igDP:Field Name="Name"> <igDP:Field.Settings> <igDP:FieldSettings> <igDP:FieldSettings.LabelPresenterStyle> <Style TargetType="{x:Type igDP:LabelPresenter}"> <EventSetter Event="Loaded" Handler="OnNameLabelLoaded" /> </Style> </igDP:FieldSettings.LabelPresenterStyle> </igDP:FieldSettings> </igDP:Field.Settings> </igDP:Field> <igDP:Field Name="Status" /> </igDP:FieldLayout.Fields> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts></igDP:XamDataGrid>
void OnNameLabelLoaded(object sender, RoutedEventArgs e){ // using Infragistics.Windows FrameworkElement site = Utilities.GetAncestorFromName( e.OriginalSource as DependencyObject, "PART_HeaderContentSite"); if (site == null) return; Grid siteHost = Utilities.GetAncestorFromType( site, typeof(Grid), false) as Grid; if (siteHost == null) return; foreach (UIElement elem in siteHost.Children) if (elem is CheckBox) return; CheckBox chk = new CheckBox(); chk.Click += new RoutedEventHandler(chk_Click); Grid.SetColumnSpan(chk, 3); chk.Margin = new Thickness(4, 0, 0, 0); chk.VerticalAlignment = VerticalAlignment.Center; siteHost.Children.Add(chk);}void chk_Click(object sender, RoutedEventArgs e){ // TODO: Check/uncheck all other CheckBoxes.}
It turns out that there's an easier, and cleaner, way to do this. Add this Style to the XamDataGrid's Resources collection, and you're good to go:
<Style TargetType="{x:Type igDP:HeaderPrefixArea}"> <Setter Property="Visibility" Value="Visible" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igDP:HeaderPrefixArea}"> <CheckBox Click="OnHeaderCheckBoxClick" VerticalAlignment="Center" HorizontalAlignment="Center" /> </ControlTemplate> </Setter.Value> </Setter></Style>
Hy Althea.
In my grid I have a list of countries and I set the DataSource of the grid to this Collention of country objects. My Country object has a property called Selected and this property it's bounded to the RecordSelector as you can se in this example.
To get all the selected countries from the grid I check the value of this propetry.
I think there is a property for a Record object from the grid called IsSelected to see if this Record is selected or not. Try to bind this property to the checkbox of the RecordSelector. Maybe this will help:
<CheckBox DataContext="{Binding ElementName=listNote, Path=ActiveRecord}" IsChecked="{Binding Path=IsSelected, Mode=TwoWay}" VerticalAlignment="Center" HorizontalAlignment="Center"/>
{
}
Hi. I have re-used this implementation, checkboxes are ok, as well as the header but I'm stuck now how to get the checked/selected data rows in the xamdatagrid. How to achieve this? Your reply is greatly appreciated! Your support is my pleasure. Thank you very much in advance.
Regards,
Althea
The best way to understand the structure of any WPF control's element tree is to use the free Mole and Snoop tools. I use those tools all the time when trying to do customizations of a control.
So this it's how it's called......HeaderPrefixArea......This was my problem because I didn't know how the header of the RecordSelector was called and I didn't know for what property of the grid to set the template.....
Thanks so very much. Now it's perfect......Thanks again.