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
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.
It looks like bindings on DataFormatString are not evaluated - or applied - properly in dynamically generated nested sub grids.
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.
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?
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.
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?
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.
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.
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.
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.
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.
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
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
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