Home Forums WPF controls Xceed DataGrid for WPF Can I use a ValueConverter to set a field value based on other fields?

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • jxbma
    Participant
    Post count: 2
    #50432 |

    Hi:

    I have a WPF XCeed DataGridControl.

    I’m not sure if this entirely possible using a value converter, but I thought I’d ask.

    Consider the following data

    FieldA   FieldB   FieldC   FieldD
    a         b         c       7
    a         b         d       8
    a         b         c       9

    Let’s say a rule exists that says: If FieldC == “d”
    then FieldD displays “Suprise” in the grid.

    There are two approaches to this.
    1) I can filter and massage the data before it gets passed to the DataGridControl
    and apply any rules I want to there.
    2) I implement the rule using a ValueConverter with the DataGridControl

    Is it possible to implement such a solution through WPF using a ValueConverter within the
    XCeed DataGridControl?

    If so, can someone point me to an example?

    Thanks,
    JohnB

    B.O.B.
    Participant
    Post count: 5

    I wrote some cell template resources to be applied to specific columns. One of which was to take a value that was coming in as an enum and passing it to a value converter to format it into a nice string format. The same should work for you.

    Here’s the template:

            <DataTemplate x:Key="EnumCellTemplate">
                <Grid>
                    <TextBlock x:Name="txt"
                               VerticalAlignment="Center"
                               TextTrimming="CharacterEllipsis">
                        <TextBlock.Style>
                            <Style TargetType="{x:Type TextBlock}">
                                <Setter Property="Text"
                                        Value="{Binding Converter={StaticResource EnumStr}}" />
                            </Style>
                        </TextBlock.Style>
                    </TextBlock>
                </Grid>
            </DataTemplate>

    Then in the Columns definition of the DataGridControl, you just have to define the column and set the CellContentTemplate. Something like:

    <g:DataGridControl.Columns>
       <g:Column CellContentTemplate="{StaticResource EnumCellTemplate}" FieldName="MyEnumField" />

    You can use the above to do all kinds of things – not just change d to surprise. For instance, I have another cell template that takes the value and uses that to return an ImageBrush that gets applied to a Canvas so I can display an image based on the value.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.