Home Forums WPF controls Xceed DataGrid for WPF Formatting cells

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

    Hi,

    I would like to format the cells of certain columns (for example showing a number such as 10000 as 10 000).
    I’ve been trying to find a simple way of doing this (as in .NET http://forums.xceed.com/forums/ShowPost.aspx?PostID=1278 with FormatSpecifier), but without luck.

    Can I do this with a few line of codes only?

    Imported from legacy forums. Posted by Stefan (had 1244 views)

    Xceed Support
    Member
    Post count: 5658

    This can be achieved by creating you own CellContentTemplate, that can be assigned to the columns in question:

    <local:MyFormattingConverter x:Key=”myFormattingConverter” />

    <DataTemplate x:Key=”myFormattedContentTemplate” >
    <TextBlock Text=”{Binding Path=., Converter={StaticResource myFormattingConverter}}”/>
    </DataTemplate>

    All that is left to do is to code the MyFormattingConverter class, which must implement IValueConverter.

    In the Convert() function, you can format the string however you’d like…

    I encourage looking at the SolidFoundation sample, as we used such an approach to format the Freight Column.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 559 views)

    User (Old forums)
    Member
    Post count: 23064

    One solution is to use a Converter (See WPF documentation of IValueConverter). If you choose to use this solution, I can post a sample.

    The problem with this solution is the poor result of sorting. For instance, if you have a column with integer values : 21 3 …, and the converter return a string, the sort of the column will be done on string comparaison and 21 will be order before 3 🙁

    Imported from legacy forums. Posted by Bernard (had 538 views)

    Xceed Support
    Member
    Post count: 5658

    BT, I’d like to hear more about the case you are expressing here… Sorting is normally done on the original data object, not on the content of the cell or UI representation of the cell’s content.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 425 views)

    User (Old forums)
    Member
    Post count: 23064

    Sorry, I’m a new Xceed control user and an old DevExpress user. This behavior was on DevExpress GridControl :-}.

    But, just a question : why each column has not a FormatString property to allow quicker development and loading time. I have some GridControl (in different projects) with some size, memory address, … If I have to create a IValueConverter for each format, I have to do it in a separate assembly to allow using the code in different projects. But add an assembly to the project increases the exe loading time.

    Best regards.

    Imported from legacy forums. Posted by Bernard (had 529 views)

    Xceed Support
    Member
    Post count: 5658

    The reason why we did not place a FormatString property in the original design is because we wanted to align as much as possible to the “new” WPF way of doing things ( Templates , Styles, …).

    We hear you when you indicate this as an important feature… I will add this to the feature request list for the DataGrid for WPF.

    If any other person think this is an important feature to have, please let us know.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 4390 views)

    User (Old forums)
    Member
    Post count: 23064

    It would be very useful – I understand you want to do things in a WPF way but the WPF way often requires far too much code to get even the simplest things done.

    Imported from legacy forums. Posted by Jonathan (had 447 views)

    Xceed Support
    Member
    Post count: 5658

    While removing duplicate post, I deleted Koti’s post by accident… I’m reposting it:

    Quoting Koti: I too think this as one of the very important feature.

    Sorry for any inconvenience this has caused.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 634 views)

    User (Old forums)
    Member
    Post count: 23064

    I also agree, a formatting feature will be really useful.

    Thanks

    Imported from legacy forums. Posted by Giuliano (had 1067 views)

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