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

DataFormatString Binding is ignored in nested sub grid view

14 Answers 143 Views
GridView
This is a migrated thread and some comments may be shown as answers.
ClausDC
Top achievements
Rank 1
Iron
ClausDC asked on 05 Nov 2014, 08:52 AM
I have nested sub grid views in my main grid view.

I use this technique for the sub grid:

<tk:RadGridView.HierarchyChildTemplate>
                <DataTemplate>
                    <tk:RadGridView

I use DataFormatString binding like this in the sub grid:

<tk:GridViewDataColumn DataMemberBinding="{Binding Path=CustomerObject.Birthday}"
                                       DataFormatString="{Binding Path=CustomerObject.BirthdayFormatString}"

The "Birthday" value binds just fine but for some reason, the "BirthdayFormatString" binding gets completely ignored. I don't even get a binding error in the console debug output. If I set "DataFormatString" to some constant value like "d" it formats correctly.

It seems that a binding does not get resolved correctly in nested sub grids.

Note that the same technique works fine in the main grid view.

14 Answers, 1 is accepted

Sort by
0
Boris
Telerik team
answered on 07 Nov 2014, 03:58 PM
Hello Claus,

Since the DataFormatString property of the GridViewDataColumn works in one case and in another not, this leads me to the conclusion that you have set an incorrect value to the property. For more information on the different formats, you can check the Data Formatting documentation article.

I attached a sample project that demonstrates how you can bind to the DataFormatString property and return the desired value by implementing a Converter. For some additional information you can check the DataFormatString Issue forum thread.

I hope this helps.

Regards,
Boris
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
ClausDC
Top achievements
Rank 1
Iron
answered on 10 Nov 2014, 08:25 AM
Yes, it works in one case but these two cases are different scenarios. Where it works is in the main grid, where it doesn't work is in the nested sub grids - as I described above.

It looks like bindings on DataFormatString are not evaluated - or applied - properly in dynamically generated nested sub grids.
0
Boris
Telerik team
answered on 12 Nov 2014, 04:58 PM
Hi Claus,

Could you please test the application from my previous reply and let us know if it's applicable to your scenario? However, if it isn't could you please edit it in a way that it mirrors your case?


Regards,
Boris
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
ClausDC
Top achievements
Rank 1
Iron
answered on 04 Dec 2014, 09:42 AM
Hi Boris,

this took a while because I had a lot of other stuff to do here.
I took a look at your example and it generally works. But I don't quite understand why the 'normal' binding technique that works on the main grid, doesn't work in the sub grid. Suddenly I have to use converters?

You know, in a big project, I can't just suddenly change a common practice and say "just let's use converters here guys!", this has implications down to the object model, I would have to define a converter for every property that needs formatting, and so on.

Is there no way to somehow successfully bind to a property for the format string like it works in the main grid view?
0
Boris
Telerik team
answered on 08 Dec 2014, 04:53 PM
Hello Claus,

Unfortunately without providing us with a runnable example that mirrors your case there is only one more
suggestion that I can make, which doesn't use a converter. It involves the binding of the DataFormatString property to a property from your parent row. For example, if you use the project from my reply on 07-Nov and replace the last column in XAML with this: 

<telerik:GridViewDataColumn DataFormatString="{Binding Path=DataContext.CustomFormatString, ElementName=childGrid}"
                 DataMemberBinding="{Binding DateOfBirth}"
                 UniqueName="FormattedColumn" />

you will observe that it works as expected.

Please note that this works because the DataContext of the childGrid is the parent row of the main grid.

I hope this helps.

Regards,
Boris
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
ClausDC
Top achievements
Rank 1
Iron
answered on 09 Jan 2015, 08:52 AM
Hi Boris,
I finally had time to do a small sample project.

https://www.dropbox.com/s/8ks97krm99k3qjm/TelerikGridViewTest.zip?dl=0

By the way, at design time, the designer doesn't recognize the Telerik GridView Control while at runtime it works fine, any idea why that is?
0
Dimitrina
Telerik team
answered on 13 Jan 2015, 03:50 PM
Hi,

Thank you for isolating the issue. Checking your implementation, it seems you have defined 
public string BirthdayFormatString { get { return "yyyy-MM-dd"; } } 
in the scope of the Member business object.

Why don't define it in your ViewModel similarly to the FoundingFormatString you use to format the columns in the parent GridView?

You can also use the FoundingFormatString, specifying a valid Source for the Binding.
For example:
<tk:GridViewDataColumn DataMemberBinding="{Binding Path=Birthday}"
            DataFormatString="{Binding Path=FoundingFormatString, Source={StaticResource model}}"

Let me know how this works for you.

Regards,
Dimitrina
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
ClausDC
Top achievements
Rank 1
Iron
answered on 18 Feb 2015, 03:17 PM
Sorry, what StaticResource exactly are you referencing with "model"?

The xaml code line you have provided does not work in my provided example because there is no StaticResource "model".

Can you please show me what you have in mind with referencing "model"? This has to be defined somewhere.

Just binding to a property in the ViewModel like that does not work for the child grid, as I wrote before.
0
Dimitrina
Telerik team
answered on 19 Feb 2015, 07:30 AM
Hello,

You can find attached the updated solution. Let me know how this works for you.

Regards,
Dimitrina
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
ClausDC
Top achievements
Rank 1
Iron
answered on 23 Feb 2015, 10:46 AM
Thank you.

The problem with that approach is that you create as second MainViewModel instance (besides the one created for DataContext, which is required in my setup).

When you open one of the child gridviews, a MainViewModel instance is created because of the XAML Resource declaration.

To create a new MainViewModel just for the use of the FormatStrings is not ideal I'm sure you understand.

0
Dimitrina
Telerik team
answered on 25 Feb 2015, 02:34 PM
Hello,

The DataContext of the details RadGridView is the item bound to the respective parent row. It does not expose a property FoundingFormatString and that is is why it will not work until you explicitly specify the correct Source where such a property is available. 

Regards,
Dimitrina
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Phillip
Top achievements
Rank 1
answered on 15 Aug 2016, 09:26 AM

So I have the same issue and don't have an access to Dropbox, so I can't really recognize which solution for this problem exist?

Can you please explain for a newbie why a normal binding to a DataFormatString doesn't work. In my case I can't just add a converter or other workarounds to the code!

Is it possible to fix it, because I don't see any problem by us developers? Maybe there is already a good solution, so this is my telerik version: 2016.1.217.45

0
Dilyan Traykov
Telerik team
answered on 15 Aug 2016, 03:58 PM
Hello Phillip,

As specified by my colleagues, the DataContext of the child RadGridView is the item bound to the respective parent row whereas the DataContext of the parent RadGridView is the one that is either explicitly set or that has been inherited by its parent elements.

This is due to the fact that more often than not, you would want to get a hold of some property of the element's parent object. Thus, when dealing with a nested RadGridView, you must explicitly set the Source for its binding if you want it to be other than the parent row.

I hope this clarifies things up for you. If you need any further assistance, please provide more information regarding your exact setup or open a new support ticket and I will gladly assist you further.

Regards,
Dilyan Traykov
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Phillip
Top achievements
Rank 1
answered on 16 Aug 2016, 12:11 PM

Hey Dilyan,

here is a new ticket I opened. Maybe it gets clear what I mean.

http://www.telerik.com/forums/dataformatstring-binding-issue

Hopefully I didn't open a ticket with a question that is allready answered in a previous ticket.

Greets,

Phillip

Tags
GridView
Asked by
ClausDC
Top achievements
Rank 1
Iron
Answers by
Boris
Telerik team
ClausDC
Top achievements
Rank 1
Iron
Dimitrina
Telerik team
Phillip
Top achievements
Rank 1
Dilyan Traykov
Telerik team
Share this question
or