Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
90
Checkbox in Group By Label available for only one Group by Label
posted

I actually have two issues here and any help would be appreciated.  In using the datagrid we would like the option of adding a checkbox to the label that will either select or deselect all of the child data records.  We added a checkbox to the label associated with a selection field in our data set:

<igDP:Field Name="SettingSelected" >

     <igDP:Field.Label>

          <CheckBox Name="SelectAll" Click="SelectAll_Click" />

     </igDP:Field.Label>

     <igDP:Field.Settings>

          <igDP:FieldSettings AllowEdit="True" AllowGroupBy="False" />

     </igDP:Field.Settings>

</igDP:Field>

This works well when we have not grouped by any of the fields.  We can simply set the boolean value for the SettingSelected field to whatever the label value has been set to.

When we group by fields we encounter strange behavior.  The checkbox on the label is only visible on the most current group by expansion. If we close and reopen a group by expansion the checkbox will become visible in the label and will no longer be visible in the prior label.

 A second problem probably associated with being relatively new at working with the controls is determing which group by label contained the checkbox that has been clicked.  The event brings back source information that lets us know the button but we have not been able to determine where in the grid hierarchy the checkbox that has caused the event to fire resides.

 The business scenario is that we check the box in the label and all of the child data boxes are checked (toggled).  The groupby option seems pretty cool as we would be able to quickly select all of the children in the desired groups.  If anyone has alternative that accomplishes the same result. 

 

Parents
No Data
Reply
  • 6867
    Verified Answer
    posted

     Hi,

    Instead of putting a CheckBox into the Label of a Field, you should set the FieldSetting's LabelPresenterStyle to a Style that applies a new ControlTemplate to the Label area.  That ControlTemplate contains a CheckBox.  Then, to figure out which group's CheckBox was clicked, you can walk up the element tree to the containing DataRecordPresenter, and from there figure out the context you need.  Below is the demo I made to figure this out...

    Setting up the XamDataGrid...

    <igDP:XamDataGrid DataSource="{Binding}">
      <igDP:XamDataGrid.FieldLayouts>
        <igDP:FieldLayout>
          <igDP:FieldLayout.Fields>
            <igDP:Field Name="Name" />
            <igDP:Field Name="IsCool">
              <igDP:Field.Settings>
                <igDP:FieldSettings>
                  <igDP:FieldSettings.LabelPresenterStyle>
                    <Style TargetType="{x:Type igDP:LabelPresenter}">
                      <Setter Property="Template">
                        <Setter.Value>
                          <ControlTemplate TargetType="{x:Type igDP:LabelPresenter}">
                            <CheckBox
                              Click="OnHeaderCheckBoxClick"
                              Content="Is Cool?"
                              Height="26"
                              Margin="5,10,0,0"
                              />

                          </ControlTemplate>
                        </Setter.Value>
                      </Setter>
                    </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>

    Handling the CheckBox Click events and figuring out which items to toggle the state for...

    void OnHeaderCheckBoxClick(object sender, RoutedEventArgs e)
    {
        CheckBox chk = e.OriginalSource as CheckBox;
        if (chk == null)
            return;

        var recordPres = Infragistics.Windows.Utilities.GetAncestorFromType(
            chk, typeof(DataRecordPresenter), true) as DataRecordPresenter;

        if (recordPres == null)
            return;

        DataRecord dataRec = recordPres.Record as DataRecord;
        if (dataRec == null)
            return;

        GroupByRecord groupRec = dataRec.ParentRecord as GroupByRecord;
        if (groupRec != null)
        {
            string msg = String.Format(
                "Toggle all {0} items in the '{1}' group where the value is {2}",
                groupRec.ChildRecords.Count(),
                groupRec.GroupByField.Name,
                groupRec.Value);

            MessageBox.Show(msg);
        }
        else
        {
            MessageBox.Show("Toggle all items");
        }
    }

Children