Hi,
I need to have an editor: combo box (if flag in other column is 'Y') or text box (otherwise). I know how to define any of this editor for cell but I don't know how to choose one of them dynamically base on some conditions
Thanks for any solutions/ideas
Hello,
You would have to retemplate the CellValuePresenter and manipulate the visibility of the two editors depending on the value of another cell. You can either do this with DataTriggers in the control template, or programatically in the EditModeEnded/CellUpdated, etc. events.Let me know if you need further assistance with this matter.
I have tried it but I didn't reach what I wanted.
I have defined style:
<Style x:Key="EditorStyle" TargetType="{x:Type igDataPresenter:CellValuePresenter }"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igDataPresenter:CellValuePresenter}"> <DockPanel> <Grid Margin="5,0,0,0" Width="Auto" Height="Auto"> <TextBlock x:Name="textBlock" Width="Auto" Height="Auto" Text="{TemplateBinding Content}" TextWrapping="Wrap" Margin="5,0,0,0" /> <ComboBox x:Name="dropDownList" > <ComboBoxItem>1</ComboBoxItem> <ComboBoxItem>2</ComboBoxItem> <ComboBoxItem>3</ComboBoxItem> </ComboBox> </Grid> </DockPanel> <ControlTemplate.Triggers> <DataTrigger Binding="{Binding Path=DataItem.Flag}" Value="Y"> <Setter TargetName="textBlock" Property="Visibility" Value="Hidden" /> <Setter TargetName="dropDownList" Property="Visibility" Value="Visible" /> </DataTrigger> <DataTrigger Binding="{Binding Path=DataItem.Flag}" Value="N"> <Setter TargetName="textBlock" Property="Visibility" Value="Visible" /> <Setter TargetName="dropDownList" Property="Visibility" Value="Hidden" /> </DataTrigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style>
And in grid I have set:
<igDataPresenter:Field Name="ColumnName" Label="Label"> <igDataPresenter:Field.Settings> <igDataPresenter:FieldSettings CellValuePresenterStyle="{StaticResource EditorStyle}" AllowEdit="True"/> </igDataPresenter:Field.Settings> </igDataPresenter:Field>
Then I have combobox in proper rows and in other I have textbox but - this combobox is visible always (not as usually only one entering in edit mode) and it looks ugly.
Can you give me more assistance with that, please?
Please find the attached solution.
It has two projects with different approaches of handling dynamic editors in the XamDataGrid cells. The first ("DynamicEditorTypes") is much more closer to your requirement and uses a style very similar to yours. On first look, it looks like that setting the Visibility to "Hidden" is causing this issue. You might want to consider collapsing it, because hidden reserves the space and collapsed does not.
Please let me know when you have a look at the sample and if you have further questions on the project.