Home Forums WPF controls Xceed DataGrid for WPF set multiple values with custom CellEditor

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #25788 |

    I’m hoping this is possible: I need to be able to set multiple values from a custom CellEditor. For example, if I have an object with StateProvince and Country properties, I would like to provide a CellEditor with a ComboBox of state/provinces grouped by country that would automatically set the Country property as well as the StateProvince property.

    I just don’t know what the binding in the CellEditor needs to look like to make this work because the {xcdg:CellEditorBinding} and {xcdg:CellContentBinding} don’t seem to give access to the object the entire DataRow is bound to? I tried the following but with no luck:

    {Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type xcdg:DataRow}}, Path=SourceObject.CountryName}

    Any help is appreciated, thanks.

    Imported from legacy forums. Posted by Kennie (had 2048 views)

    User (Old forums)
    Member
    Post count: 23064

    I had the same issue. You need to bind to the DataContext of the DataCell. The following is an example where I only wanted the CheckBox to be visible if another value in the object was true.

    <xcdg:Column FieldName=”DateActual” MinWidth=”40″ Title=”Actual” Width=”40″>
    <xcdg:Column.CellContentTemplate>
    <DataTemplate>
    <CheckBox HorizontalAlignment=”Center” Visibility=”<b>{Binding Path=DataContext, Converter={StaticResource VisibleIfCustomDate}, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type xcdg:DataCell}}}</b>” IsChecked=”{Binding Mode=OneWay}” />
    </DataTemplate>
    </xcdg:Column.CellContentTemplate>
    <xcdg:Column.CellEditor>
    <xcdg:CellEditor>
    <xcdg:CellEditor.EditTemplate>
    <DataTemplate>
    <CheckBox HorizontalAlignment=”Center” Visibility=”<b>{Binding Path=DataContext, Converter={StaticResource VisibleIfCustomDate}, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type xcdg:DataCell}}}</b>” IsChecked=”{xcdg:CellEditorBinding}” />
    </DataTemplate>
    </xcdg:CellEditor.EditTemplate>
    </xcdg:CellEditor>
    </xcdg:Column.CellEditor>
    </xcdg:Column>

    Hope this was helpful.

    Imported from legacy forums. Posted by Wally (had 3342 views)

    User (Old forums)
    Member
    Post count: 23064

    You might also want to bind to a property on the current row’s DataItem.

    <ComboBox DockPanel.Dock=”Bottom” ItemsSource=”{Binding RelativeSource={RelativeSource AncestorType={x:Type xcdg:DataCell}},Path=((SomeObject)DataContext).PropertyA}” IsEditable=”True” Foreground=”Black” />

    Imported from legacy forums. Posted by Echilon (had 678 views)

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.