DataFormatString Issue

7 posts, 0 answers
  1. Oliver Cox
    Oliver Cox avatar
    7 posts
    Member since:
    Nov 2009

    Posted 09 Jul 2010 Link to this post

    Hi,

    I am having a problem achieving what I want to with the WPF RadGridView and the DataFormatString property. I have a grid with various numeric values and need to set the format of these values at a row level as opposed to a column level. It has not been possible to bind the DataFormatString to a property of the row data item.

    I have tried to use control templates both declarative and programmatic with template selector but the performance is not good compared with the standard GridViewDataColumn implementation.

    Is there any way that I can bind to this property or any other suggestions as to how I achieve the requirement of formatting the data of a cell based a property of the row dataitem.

    To explain a little further here is my object:

    public class PlanningItem
    {
        public string ItemName { get; set; }
        public string ItemFormat { get; set; }
        public double ItemValue { get; set; }
    }

    And the GridView would look something like:

    <telerik:RadGridView AutoGenerateColumns="False" Name="radGridView1" ItemsSource="{ Binding Path=PlanningItems }">
       <telerik:RadGridView.Columns>
            <telerik:GridViewDataColumn UniqueName="ItemName" Header="Item Name" DataMemberBinding="{ Binding Path=ItemName }" IsReadOnly="True" />
            <telerik:GridViewDataColumn UniqueName="ItemValue" Header="Item Value" DataMemberBinding="{ Binding Path=ItemValue}" DataFormatString="{ Binding ItemFormat }"/>
    </telerik:RadGridView.Columns>
    </telerik:RadGridView>

    Thanks

    Oliver
  2. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 12 Jul 2010 Link to this post

    Hello Oliver Cox,

    Have you tried using a Converter?

    Kind regards,
    Veskoni
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
  4. Oliver Cox
    Oliver Cox avatar
    7 posts
    Member since:
    Nov 2009

    Posted 12 Jul 2010 Link to this post

    Hi,

    I'm not sure how the converter would work as the value passed to the converter is not the row dataitem.

    The markup I used is

    DataStringFormat="{ Binding Converter={ StaticResource cellFormatConverter }}"


    Thanks

    Oliver
  5. Oliver Cox
    Oliver Cox avatar
    7 posts
    Member since:
    Nov 2009

    Posted 12 Jul 2010 Link to this post

    Hi,

    Could the following post also be used here?

    http://blogs.telerik.com/blogs/posts/10-05-13/how_to_custom_percentage_column_with_radgridview_radprogressbar_and_radslider_for_silverlight_and_wpf.aspx

    The approach being that I will override CreateCellElement() and apply the format to the binding.

    Thanks

    Oliver
  6. Steve Evans
    Steve Evans avatar
    23 posts
    Member since:
    May 2010

    Posted 14 Jul 2010 Link to this post

    HI, 

    I am faced with a situation where I need to show numeric data in GridViewDataColumn and need to format the string that is shown in the column such that it shows to x number of decimal places. I know that this can be achieved using the DataFormatString however, the number of decimal places that I need to format to can be selected by the user and so I can not just use a static DataFormatString. 

    I have looked at using a converter in this scenario but this also doesn't seem to fit very well as I would want to pass in the precision/number of required decimal places to the converter from a bound property of the data context of the grid, which cannot be done as the ConverterParameter is not a dependency property.

    What would  you recommend in this scenario? Any info would be great.

    Thanks, Steve
  7. Steve Evans
    Steve Evans avatar
    23 posts
    Member since:
    May 2010

    Posted 14 Jul 2010 Link to this post

    Hi, 

    I have managed to resolve the issue that I raised regarding having the DataFormatString vary depending upon the user input.

    Thinking about it now it seems obvious that all I had to do was to bind the DataFormatString property of the GridViewColumn to a property on the data context but when I tried this previously I must have been doing something wrong.

    Anyway, problem solved.

    Steve.
  8. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 14 Jul 2010 Link to this post

    Hello guys,

    You can pass the whole business object to the converter like so:

    <telerik:GridViewDataColumn DataMemberBinding="{Binding RelativeSource={RelativeSource AncestorType=telerik:GridViewRow},
    Converter={StaticResource myConverter}}" />

    Now, the e.Value in the Convert method will hold the GridViewRow. You can cast its DataContext property to the type of your business object.

    Also, you might find this blog post useful:
    Binding a converter parameter

    Sincerely yours,
    Veskoni
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top
UI for WPF is Visual Studio 2017 Ready