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
65
Clicking Parent checkbox, programatically check Filtered Children checkboxes
posted

I am using Xamdatagrid and binding hierarchical data (2 levels - Parent & Child). Columns are different in Parent & Child. Using 2 layouts in single Xamdatagrid to achieve the same. Both parent and child has filters. First column of Parent & Child having checkbox. Checking checkbox against parent record, should programmatically check all Filtered child record's checkboxes. I am unable to get filtered children records in code behind to programmatically check checkboxes. Attaching example image below. Child records actually filtered. Using Infragistics 12.2. Please help asap.

  • 65
    Verified Answer
    Offline posted

    After lot of struggle, I could fix this.

    Xaml

    <igDP:Field Label="" Name="IsSelected" Width="auto">
      <igDP:Field.Settings>
        <igDP:FieldSettings AllowEdit="True" AllowRecordFiltering="False">
          <igDP:FieldSettings.EditorStyle>
            <Style TargetType="{x:Type igEditors:XamCheckEditor}">
              <EventSetter Event="ValueChanged" Handler="cHeaderValueChanged"/>
            </Style>
          </igDP:FieldSettings.EditorStyle>
        </igDP:FieldSettings>
      </igDP:Field.Settings>
    </igDP:Field>

    Code Behind

            void cHeaderValueChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
            {
                XamCheckEditor editor = sender as XamCheckEditor;
                editor.EndEditMode(true, true);

                if (editor.IsChecked == true)
                    setChildrenCheckBoxes(sender, true);
                else
                    setChildrenCheckBoxes(sender, false);
            }

            private void setChildrenCheckBoxes(object sender, bool isChecked)
            {
                DataRecordPresenter r = Utilities.GetAncestorFromType(sender as DependencyObject, typeof(DataRecordPresenter), false) as DataRecordPresenter;

                if (r == null)
                    return;

                if (r.DataRecord == null)
                    return;

                if (r.DataRecord.DataItem == null)
                    return;

                if (r.DataRecord.HasChildren && r.DataRecord.ViewableChildRecords.Count == 1 && r.DataRecord.ViewableChildRecords[0].HasChildren)
                {
                    var filteredChilds = r.DataRecord.ViewableChildRecords[0].ViewableChildRecords.Where(x => x.IsDataRecord);
                    foreach (var child in filteredChilds)
                    {
                        UnitLevelProduct product = (UnitLevelProduct)(((DataRecord)child).DataItem);
                        product.IsSelected = isChecked;
                    }
                }
            }