Welcome to the Xceed Community | Help
Community Search  
More Search Options

Attach ValueConverter to GridViewColumn

Sort Posts: Previous Next
  •  01-19-2012, 10:56 AM Post no. 31581

    Attach ValueConverter to GridViewColumn

    Hello everybody

     I have written a converter class(implementing IValueConverter) which converts a code that comes from the database (for example "CTY") into a more user friendly description (for example "City"). I want to use the converter on a single Column in my XCeed WPF Datagridcontrol, but I do not know to which property I must set the Converter to. I also tried to attach it to a DataCell using a style (see below) but I think that is not necessary since the converter should apply to only one column and not every cell.

    This is what I have now:

      <utils:BudgettaireEntiteitConverter x:Key="BudgettaireEntiteitConverter" />
           
            <Style TargetType="{x:Type xcdg:DataCell}">
                <Setter Property="Content" Value="{Binding Converter={StaticResource BudgettaireEntiteitConverter}}" />
            </Style>

     When I come into the Convert function the value is of type Xceed.Wpf.DataGrid.EmptyDataItem which ofcoure throws an error when I want to convert it to a certain value.

    How should I apply the converter to a column? Do you guys have any suggestions?

    More examples or code can be provided if asked for. I hope my problem is a bit clear for you.

    Filed under:
  •  01-24-2012, 9:38 PM Post no. 31606 in reply to 31581

    Re: Attach ValueConverter to GridViewColumn

    Hi Jelle, 

    This can by done at the level of the Column by changing its CellContentTemplate, it should look somethijng like this: 

     

    <xcdg:DataGridControl>

                    <xcdg:DataGridControl.Columns>

                        <xcdg:Column FieldName="Test">

                            <xcdg:Column.CellContentTemplate>

                                <DataTemplate>

                                    <TextBlock Text="{Binding Converter={StaticResource  BudgettaireEntiteitConverter }}"

                                </DataTemplate>

                            </xcdg:Column.CellContentTemplate>

                        </xcdg:Column>

                    </xcdg:DataGridControl.Columns> 


    Best Regards,

    Michel Dahdah
    Technical Support
    Xceed Software inc.
  •  02-07-2012, 11:16 AM Post no. 31648 in reply to 31606

    Re: Attach ValueConverter to GridViewColumn

    Thanks for your reply.

    I solved it with a different approach:

     </xcdg:Column>
          <xcdg:Column Title="Budgettaire entiteit"
                       FieldName="BudgettaireEntiteit"
                       Visible="False"
                       ReadOnly="True" >
            <xcdg:Column.DisplayMemberBindingInfo>
              <xcdg:DataGridBindingInfo Path="BudgettaireEntiteit"
                                        ReadOnly="True"
                                        Converter="{StaticResource BudgettaireEntiteitConverter}"/>
            </xcdg:Column.DisplayMemberBindingInfo>
          </xcdg:Column>

    But both seem to be a working solution :)

View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.