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
555
Disallow editing for certain rows
posted

We want to dissallow the possibility to edit for single rows depending on a boolean in the XamDataGrid.

What is the best way of doing this. I know how to deactivate single columns but I want deactivate the row.

I have attached a sample solution in which I want to activate or deactivate editing depending on the boolean "IsEditable".

XamDataGridDeactivateWholeRow.zip
  • 16495
    Offline posted

    Hello,

    thank you for the attached project.

    You can implement a couple of approaches here:

    approach 1:

    You can handle the EditModeStaring event of XamDataGrid and in the event  handler you can check whether the IsEditible property from DataItem is equal to False and if it is you can set e.Cancel to true:

    private void XamDataGrid_EditModeStarting(object sender, Infragistics.Windows.DataPresenter.Events.EditModeStartingEventArgs e)
    {
        if ((e.Cell.Record.DataItem as Person).IsEditable == false)
            e.Cancel = true;
    }

    approach 2:

    Style for the editor where can check DataItem's IsEditible and if it is equal to False you can  set its IsReadOnly Property to True, but you will have to create Style for all kind of Editors that your XamDataGrid will use where you want to make Cells ReadOnly:

    <Style TargetType="{x:Type igEditors:XamTextEditor}" >
        <Style.Triggers>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type controls:CellValuePresenter}}, Path=Record.DataItem.IsEditable}" Value="false">
                <Setter Property="IsReadOnly" Value="True"/>
            </DataTrigger>
        </Style.Triggers>
    </Style>

    approach 3:

    Style for DataRecordPresenter,DataRecordCellArea or CellValuePresenter. In it you can access the DataItem's IsEditible in a DataTrigger and depending on the value can set the IsEnable property:

    <Style TargetType="{x:Type controls:DataRecordCellArea}" >
    <Style.Triggers>
        <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Record.DataItem.IsEditable}" Value="false">
            <Setter Property="IsEnabled" Value="False"/>
        </DataTrigger>
    </Style.Triggers>
    </Style>

    I have attached a modified version of your project, where you can test these approaches.

     Please let me know if this helps you or you need further assistance on this matter.

    Sincerely,
    Zhivko
    Associate Software Developer

    XamDataGridDeactivateWholeRow_2.zip