Vikas
Vikas

Reputation: 178

Disable editing of cells in XamGrid

I am working on XamGrid binded with the DataTable. I want to disable the editing of cells on a specific condition. I have created the behavior of the XamGrid.

Can suggest solution according to my requirement?

Upvotes: 0

Views: 1476

Answers (3)

Vikas
Vikas

Reputation: 178

This is working for me:

 dataGrid.EditingSettings.AllowEditing = EditingType.None;

Upvotes: 0

Kylo Ren
Kylo Ren

Reputation: 8813

Use style of CellValuePresenter:

<Style x:Key="DisableForCTE" TargetType="{x:Type iDP:CellValuePresenter}" >
    <Style.Triggers>
        <DataTrigger Binding="{Binding Path=DataItem.CTESubLocation}" Value="No">
              <Setter Property="IsEnabled" Value="False"></Setter>                        
         </DataTrigger>                    
     </Style.Triggers>
</Style>

Also if condition is predefined, cells can be disabled as column level:

 <iDP:Field Name="LatestEffectiveDate" Label="Latest Effective Date" >
 <iDP:Field.Settings>
     <iDP:FieldSettings AllowEdit="False">                                       
     </iDP:FieldSettings>
  </iDP:Field.Settings>

Upvotes: 1

Ilan
Ilan

Reputation: 2782

Try to define style with data triggers:

        <igWPF:XamDataGrid.Resources>

        ...
        <Style TargetType="CellValuePresenter">
            <Style.Triggers>
                <!--one condition based trigger - condition is inside the cell data context-->
                <DataTrigger Binding="{Binding Path=DataItem.ConditionA}" Value="True">
                    <Setter Property="IsEnabled" Value="False"/>
                </DataTrigger>
                <!--multiple condition based trigger - condition is inside the cell data context-->
                <MultiDataTrigger>
                    <MultiDataTrigger.Conditions>
                        <Condition Binding="{Binding Path=DataItem.ConditionA}" Value="True" />
                        <Condition Binding="{Binding Path=DataItem.ConditionB}" Value="False" />
                    </MultiDataTrigger.Conditions>
                    <MultiDataTrigger.Setters>
                        <Setter Property="IsEnabled" Value="False"></Setter>
                    </MultiDataTrigger.Setters>
                </MultiDataTrigger>
            </Style.Triggers>
        </Style>

        ...

    </igWPF:XamDataGrid.Resources>

Regards.

Upvotes: 2

Related Questions