Nested properties in RadPropertyGrid with several items and intersection

1 Answer 98 Views
PropertyGrid
Markus
Top achievements
Rank 1
Markus asked on 24 Feb 2023, 03:39 PM

Hi

I have a RadPropertyGrid, being defined as:

       <telerik:RadPropertyGrid Item="{Binding ObjectBound, Mode=OneWay}" Width="300" Name="propertyGrid2"
                                 Grid.Column="1"
                                 VerticalAlignment="Stretch"
                                 VerticalContentAlignment="Stretch"
                                 NestedPropertiesVisibility="Visible"
                                 AutoGeneratePropertyDefinitions="True"
                                 SelectionMode="Multiple"
                                 PropertySetMode="Intersection"
                                 telerik:PropertySet.ShouldAddNullForNonMatchingValues="True"

 

where I would like to bind 0...n items

 

Let's say all of those items belong to the class Car

 

  public class CarEngine
    {
        public int PowerKW { get; set; }
        public int DisplacementCCM { get; set; }

    }
    public class Car
    {
        public Car()
        {
            Engine = new ();
        }
        public string Manufacturer { get; set; }
        public string Color { get; set; }
        public CarEngine Engine { get; set; }

    }

In the code behind I have a property to bind to the PropertyGrid

 

public object ObjectBound
        {
            get;
            set;
        }

and will create the items like this:

 

  Car c = new Car();
            c.Manufacturer = "Honda";
            c.Engine.PowerKW = 110;
            c.Engine.DisplacementCCM = 1799;
            c.Color = "black";


            Car c2 = new Car();
            c2.Manufacturer = "BMW";
            c2.Engine.DisplacementCCM = 2199;
            c2.Engine.PowerKW = 150;
            c2.Color = "black";

            List<Car> list = new();
            list.Add(c);
            list.Add(c2);

now first, I will bind just one car instance to the RadPropertyGrid:

            this.ObjectBound = c;

Here I can expand the nested engine instance and can write to each field which is absolutety perfect!

Then we have a second use case where I would like to bind to the list with two cars and get their common attributes while differerent properties will be displayed empty:

      this.ObjectBound = list;

Therefore I had choosen "Intersection" for the propertysetmode of the RadPropertyGrid

For the primitive Attributes Color (shared between both cars) and Manufacturer (different) that will work just fine. 

 

 

But as one can see the nested Attribute "Engine" cannot be set as it not able to be expanded! I'd like to set e.g. a common displacement for both of the two cars. How can I realize such a behaviour as it is required from business?

 

thanks!

         

1 Answer, 1 is accepted

Sort by
0
Stenly
Telerik team
answered on 01 Mar 2023, 01:48 PM

Hello Markus,

With the current implementation of the RadPropertyGrid control, the Property Sets functionality does not support nested properties.

In scenarios where the property sets functionality has to be used in conjunction with nested properties, computed properties that point to the nested ones could be created in your business object. However, there will be no collapse or expansion options (referring to the first image that you have provided) as the nested properties will be modified via the additional computed ones. For example, using the provided classes (Car and CarEngine) a new property could be created in the Car class, which will point to the value of the PowerKW property of the CarEngine instance.

With this being said, I hope the provided information will be of help to you.

Regards,
Stenly
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
PropertyGrid
Asked by
Markus
Top achievements
Rank 1
Answers by
Stenly
Telerik team
Share this question
or