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
180
how to check programmically a checkbox in datagrid (dataitem.ischecked) ?
posted

Dear,

How can I programmically check a checkbox in my datagrid that is not part of the datasource ?

I fill my datagrid based on a stored procedure and I have added a checkbox column in front as explained in other posts here.  Some of the records however have to be checked but I don't find the source code to programmically check the item (dataitem) while iterating through the records (datarecords) ? Can anyone give me an example of the right source code ? Thank you very much

 

C# Code iteration :

public void IterateMainGridRecords(RecordCollectionBase records)
        {
            try
            {
                foreach (Record rec in records)
                {

                    if (rec.RecordType == RecordType.GroupByField || rec.RecordType == RecordType.GroupByFieldLayout)
                    {
                        GroupByRecord groupRecord = (GroupByRecord)rec;


                        if (groupRecord.HasChildren)
                            IterateMainGridRecords(groupRecord.ChildRecords, strIterateProcess);
                    }
                    else if (rec.RecordType == RecordType.DataRecord)
                    {
                        DataRecord dataRecord = (DataRecord)rec;

                    => how to check the Checkbox here for some records ???

                    }

 

XAML code for datagrid checkbox

<!-- 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}" Checked="fAddAllRecordsToCheckList" Unchecked="fRemoveAllRecordsFromCheckList" />
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>

  • 138253
    Offline posted

    Hello,

     

    It has been a while since you have made your post, in case you still need support I will be glad to assist you further. I suppose the other community members can benefit from this answer as well. So I have been looking through your post and I suggest you see in the Feature Browser under xamDataGrid / Control Composition / CheckBox in Record Selectors section where it is shown how to add CheckBoxes. There it is used a ViewModel class which has two properties one of type Person and the other of type bool which is bound to the IsSelected property of the Record so when you iterate trough the Records you can check this property which has the same Value as the one used for Selector.

     

    Feel free to write me if you have any other questions.