This is a migrated thread and some comments may be shown as answers.

DataFormatString Issue

6 Answers 480 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Oliver Cox
Top achievements
Rank 1
Oliver Cox asked on 09 Jul 2010, 05:18 PM
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

6 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 12 Jul 2010, 07:21 AM
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
0
Oliver Cox
Top achievements
Rank 1
answered on 12 Jul 2010, 09:25 AM
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
0
Oliver Cox
Top achievements
Rank 1
answered on 12 Jul 2010, 10:39 AM
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
0
Steve Evans
Top achievements
Rank 1
answered on 14 Jul 2010, 08:55 AM
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
0
Steve Evans
Top achievements
Rank 1
answered on 14 Jul 2010, 02:05 PM
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.
0
Veselin Vasilev
Telerik team
answered on 14 Jul 2010, 02:45 PM
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
Tags
GridView
Asked by
Oliver Cox
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Oliver Cox
Top achievements
Rank 1
Steve Evans
Top achievements
Rank 1
Share this question
or