WPF DataGrid Cell Properties

Nov 21, 2008 at 12:45 PM
Hi EveryOne,

I have a problem in enabling and Disabling the Controls in the WPF:DataGrid,
I am trying to Disable the TextBoxes in the DataGrid when the ComboBox in the same DataGrid gets the SelectedIndex as 0. The TextBoxes of the same row in which the ComboBox's SelectedIndex is 0 should be disabled.

For example, lets say there are 6 columns and 10 rows in a DataGrid,
ComboBox is in Column 3, rest are the TextBox Columns. If I set the ComboBox's SelectedIndex to 0(ZERO) of Row 3, then the TextBoxes in the Column 4 and 5 of the respective row(i.e., Row 3) has to be disabled,

Can Anybody please, help me out with this Issue????

Thank you in Advance.....
Coordinator
Nov 21, 2008 at 5:48 PM
Hi chetanarayan,

Something like the following should work....

<DataGrid>
    <DataGrid.Columns>
        <DataGridComboBoxColumn SelectedItemBinding={Binding Path=Cake} />
        <DataGridTextBoxColumn>
            <dg:DataGridTextColumn.EditingElementStyle>
                  <Style TargetType="{x:Type TextBox}">
                       <Style.Triggers>
                          <DataTrigger Binding="{Binding Path=Cake}" Value="Chocolate">
                              <Setter Property="IsEnabled" Value="False"></Setter>
                          </DataTrigger>
                      </Style.Triggers>
                  </Style>
              </dg:DataGridTextColumn.EditingElementStyle>
        </DataGridTextBoxColumn>
    </DataGrid.Columns>
</DataGrid>

Basically have a trigger for TextBox bound to the same property as is ComboBox and enable it appropriately.
Nov 24, 2008 at 4:05 AM
Thanks a lot Mr.Vamsee....