Nested Property Value (Long Namespace Name)

7 posts, 1 answers
  1. Sayyed Hossein
    Sayyed Hossein avatar
    23 posts
    Member since:
    Oct 2012

    Posted 13 Oct 2012 Link to this post


    assume i have a property named MyProperty of type MyType with namespace address of :
    NameSpaceMain.Namespace2.Namespace3. ... .LastNameSpace.MyType

    as you know when using nested properties the value of the main property (who owns the nested properties) is shown somehow like this in tyhe propertygrid:

    + MyProperty                      NameSpaceMain.Namespace2.Namespace3. ... LastNameSpace.MyType
        nestedproperty1                  true
        nestedproperty2                  false
        nestedproperty3                  true
        nestedproperty4                  false

    what should i do to just show the last part (MyType) or even some other manual Name as the value of my property in the peopertygrid
    thank you in advance for your answer
  2. Answer
    Yoan avatar
    1128 posts

    Posted 18 Oct 2012 Link to this post


     In order to achieve your goal you can override the ToString method of your "MyProperty" class like so:

    public override string ToString()
                return String.Format( this.Namespace1.Namespace2.LastNamespace);

    Please find attached sample project that meets your requirements.

    All the best,
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. Sayyed Hossein
    Sayyed Hossein avatar
    23 posts
    Member since:
    Oct 2012

    Posted 20 Oct 2012 Link to this post

    thank you very much dear yoan for your helpful answer :)
  4. Andrei
    Andrei avatar
    1 posts
    Member since:
    Mar 2015

    Posted 28 Apr 2015 Link to this post

    Hey there,

     Regarding your answer: how can I make it so that the Header updates if the ToString method content changes?



  5. Stefan
    Stefan avatar
    796 posts

    Posted 29 Apr 2015 Link to this post

    Hello Andrei,

    Basically, in such scenario the parent object needs to listen for a property change in its nested object. I have modified the sample project in a way that demonstrates how this can be achieved.

    I hope this helps.

    Best Regards,

    See What's Next in App Development. Register for TelerikNEXT.

  6. rick
    rick avatar
    6 posts
    Member since:
    Jan 2016

    Posted 22 Mar 2016 in reply to Stefan Link to this post

    Hi Stefan,

    Sorry for posting on an old thread. But I'm wondering is there a way to achieve this (just need display constant text) without overriding ToString() method?

  7. Stefan
    Stefan avatar
    796 posts

    Posted 24 Mar 2016 Link to this post

    Hello Rick,

    It is possible to bind a given PropertyDefinition to a particular property of an object. With such approach, however, the Nested properties will try to resolve their Binding within this particular property. You can take a look at the code snippet below, as an example.
    <telerik:PropertyDefinition DisplayName="Department"
                                Binding="{Binding Department.Country}">
            <telerik:PropertyDefinition DisplayName="Country"
                                        Binding="{Binding Country}"/>
            <telerik:PropertyDefinition DisplayName="ID"
                                        Binding="{Binding ID}"/>

    With this setup, the PropertyDefinition's Binding will search for the Country and ID properties within the Country property. So, I suggest you sticking to the approach of overriding the ToString() method.

    Stefan X1
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top