DataFormatString Binding is ignored in nested sub grid view

15 posts, 0 answers
  1. ClausDC
    ClausDC avatar
    58 posts
    Member since:
    Feb 2010

    Posted 05 Nov 2014 Link to this post

    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.
  2. Boris
    Admin
    Boris avatar
    276 posts

    Posted 07 Nov 2014 Link to this post

    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.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. ClausDC
    ClausDC avatar
    58 posts
    Member since:
    Feb 2010

    Posted 10 Nov 2014 in reply to Boris Link to this post

    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.
  5. Boris
    Admin
    Boris avatar
    276 posts

    Posted 12 Nov 2014 Link to this post

    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.

     
  6. ClausDC
    ClausDC avatar
    58 posts
    Member since:
    Feb 2010

    Posted 04 Dec 2014 in reply to Boris Link to this post

    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?
  7. Boris
    Admin
    Boris avatar
    276 posts

    Posted 08 Dec 2014 Link to this post

    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.

     
  8. ClausDC
    ClausDC avatar
    58 posts
    Member since:
    Feb 2010

    Posted 09 Jan 2015 in reply to Boris Link to this post

    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?
  9. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 13 Jan 2015 Link to this post

    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.

     
  10. ClausDC
    ClausDC avatar
    58 posts
    Member since:
    Feb 2010

    Posted 18 Feb 2015 in reply to Dimitrina Link to this post

    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.
  11. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 19 Feb 2015 Link to this post

    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.

     
  12. ClausDC
    ClausDC avatar
    58 posts
    Member since:
    Feb 2010

    Posted 23 Feb 2015 in reply to Dimitrina Link to this post

    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.

  13. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 25 Feb 2015 Link to this post

    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.

     
  14. Phillip
    Phillip avatar
    4 posts
    Member since:
    Mar 2016

    Posted 15 Aug Link to this post

    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

  15. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    371 posts

    Posted 15 Aug Link to this post

    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.
  16. Phillip
    Phillip avatar
    4 posts
    Member since:
    Mar 2016

    Posted 16 Aug in reply to Dilyan Traykov Link to this post

    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

Back to Top
UI for WPF is Visual Studio 2017 Ready