Hi,
In a xamdatagrid, is it possible to disable a particual cell based on the value selected in another cell which is prior to that.
For e..g.,
Say we have a grid with Name and Age as columns, wherein Name Field is like popup listing giving employee names. After the selection of employee name, age automatically fills in and that particular cell got to be disabled.
Could you please tell me how this could be achieved?
Thanks,
Balaj Rajendran (WK - CCH, Torrance)
Hello Balaj,
You can do that, by creating a style for the CellValuePresenter. You should apply that style to only the Age field, as it will disable itself (the cell) based on a condition - HasContent:
<Style TargetType="{x:Type igDP:CellValuePresenter}">
<Style.Triggers>
<Trigger Property="HasContent" Value="True">
<Setter Property="IsEnabled" Value="False"/>
</Trigger>
</Style.Triggers>
</Style>
Let me know if that works in your scenario.
Hi, I've such situation: I have a field bound to boolean property of my data item. I need to disable editing of this field when data item has some specific states. If I set IsEnabled property of CellValuePresenter to False it's not possible to check/uncheck editor, but checkbox looks like it's enabled. I achieved correct behavior using style below. But, I'm curious if there is more simple way for that.
<Style x:Key="Checked" TargetType="idp:CellValuePresenter"> <Setter Property="IsEnabled" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type idp:DataRecordCellArea}}, Path=Record.DataItem, Converter={local:DataItemToCheckedFieldIsEnabledConverter}}"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="idp:CellValuePresenter"> <CheckBox IsChecked="{TemplateBinding Value}" IsEnabled="{TemplateBinding IsEnabled}" HorizontalAlignment="Center" VerticalAlignment="Center"/> </ControlTemplate> </Setter.Value> </Setter> </Style>
Hello,
Well, you could simplity your binding a little bit : you remove the relativesource expression, as the DataContext of the CVP is the record, so the Path will be just DataItem.
Another way would be to set the Tag property (for example of the Record or the Cell) and bind the IsEnabled property to that, avoiding the converter.
Alex, I meant different thing: is it possible to make XamCheckEditor look like disabled when CellValuePresenter is disabled. I tried to change CheckBox to XamCheckEditor in a ControlTemplate and it still looks enabled. Is it a bug in its default style?
Another problem that I have with this style is when I check/uncheck checkbox in cell CellUpdating and CellUpdated events aren't fired.
Second problem is fixed: I've just modified IsChecked property binding to:
IsChecked="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Value, Mode=TwoWay}
But, I'm still wondering if there is a bug in XamCheckEditor style.