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
240
how to create dynamic cell editor?
posted

i using the xamDataGrid. i want to create dynamic cell editor... for example, when i click cell #2, if the value of the cell #1 is 3, i want to display the editor for date and time, and if the value of the cell #1 is 4, i want to display the editor for custom data.

  • 6867
    Verified Answer
    posted

    Hi,

    I think the following technique should satisfy your requirement...

    <Window.Resources>
      <Style x:Key="VariableCellEditorStyle" TargetType="{x:Type igDP:CellValuePresenter}">
        <Style.Triggers>
          <DataTrigger Binding="{Binding Path=Cells[SomeField].Value}" Value="0">
            <Setter Property="Template">
              <Setter.Value>
                <ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">
                  <TextBox
                    Background="LightBlue"
                    Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Value}"
                    />
                </ControlTemplate>
              </Setter.Value>
            </Setter>
          </DataTrigger>
          <DataTrigger Binding="{Binding Path=Cells[SomeField].Value}" Value="1">
            <Setter Property="Template">
              <Setter.Value>
                <ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">
                  <igEditors:XamTextEditor
                    Background="Gray"
                    IsReadOnly="True"
                    Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Value}"
                    />
                </ControlTemplate>
              </Setter.Value>
            </Setter>
          </DataTrigger>
        </Style.Triggers>
      </Style>
    </Window.Resources>

    <igDP:XamDataGrid x:Name="xamDG">
      <igDP:XamDataGrid.FieldLayouts>
        <igDP:FieldLayout>
          <igDP:FieldLayout.Fields>
            <igDP:Field Name="State">
              <igDP:Field.Settings>
                <igDP:FieldSettings CellValuePresenterStyle="{StaticResource VariableCellEditorStyle}" />
              </igDP:Field.Settings>
            </igDP:Field>
          </igDP:FieldLayout.Fields>
        </igDP:FieldLayout>
      </igDP:XamDataGrid.FieldLayouts>
    </igDP:XamDataGrid>

    Josh