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

Nested Property Value (Long Namespace Name)

6 Answers 51 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Sayyed Hossein
Top achievements
Rank 1
Sayyed Hossein asked on 13 Oct 2012, 06:40 AM
hi

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

6 Answers, 1 is accepted

Sort by
0
Accepted
Yoan
Telerik team
answered on 18 Oct 2012, 07:28 AM
Hi,

 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,
Yoan
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Sayyed Hossein
Top achievements
Rank 1
answered on 20 Oct 2012, 07:41 AM
thank you very much dear yoan for your helpful answer :)
0
Andrei
Top achievements
Rank 1
answered on 28 Apr 2015, 11:13 AM

Hey there,

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

 Thanks,

Andrei

0
Stefan
Telerik team
answered on 29 Apr 2015, 04:01 PM
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,
Stefan
Telerik
 

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

 
0
rick
Top achievements
Rank 1
answered on 22 Mar 2016, 07:37 AM

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?

0
Stefan
Telerik team
answered on 24 Mar 2016, 12:21 PM
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"
                            Description="Department"
                            Binding="{Binding Department.Country}">
    <telerik:PropertyDefinition.NestedProperties>
        <telerik:PropertyDefinition DisplayName="Country"
                                    Binding="{Binding Country}"/>
        <telerik:PropertyDefinition DisplayName="ID"
                                    Binding="{Binding ID}"/>
    </telerik:PropertyDefinition.NestedProperties>
</telerik:PropertyDefinition>

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.

Regards,
Stefan X1
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
PropertyGrid
Asked by
Sayyed Hossein
Top achievements
Rank 1
Answers by
Yoan
Telerik team
Sayyed Hossein
Top achievements
Rank 1
Andrei
Top achievements
Rank 1
Stefan
Telerik team
rick
Top achievements
Rank 1
Share this question
or