0

Hey

Firstly, I have a WPF solution with n amount of classes.

I have instantiated the classes and assigned them to an array of type Object. So far I have 2 elements to my array (Class A and Class B) I am simply trying to add this array to the SelectedObjects property of the PropertyGrid - no suprise it don't work. Can anyone see what I may be doing wrong?

Here is some sample code which mimics exactly what I have at the moment:

class A
    {
        // Some sample properties
        private double seconds;

        public double Hours
        {
            get { };
            set { };
        }
        ...
    }

class B
    {
       // Some sample properties
        private double seconds;

        public double Hours
        {
            get { };
            set { };
        }
         ...
    }

In the Window1.xaml code behind file I have:

// Create two class objects (one of Class A and one of Class B)
      A ClassAInstance = new A();
      B ClassBInstance = new B();

      // Define an array of type Object to hold the above instances
      Object[] myObjs = new Object[1];
    
       // Add the instances to the array
      myObjs[0] = ClassAInstance;
      myObjs[1] = ClassBInstance;

       // HERE IS MY PROBLEM - this doesn't seem to work :(
       PropertyGrid1.SelectedObjects = myObjs;

If I replaced the last line of code with this:

PropertyGrid1.SelectedObject = ClassAInstance;

or

PropertyGrid1.SelectedObject = ClassBInstance

It would have worked just fine, however this only permits for the use of ONE Objects properties, I need multiple Objects (properties) to display in ONE PropertyGrid.

Many thanks for help with my problem

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by Blorgle
0

The PropertyGrid only allows one object at the time.
Perhaps you could implement the ContextMenuStrip of the PropertyGrid. By right clicking the PropertyGrid you could then select between different objects.

0
Object[] myObjs = new Object[1];

should be

Object[] myObjs = new Object[2];

or even

PropertyGrid1.SelectedObjects = new object [] { new A(), new B() };

Edited by Blorgle: n/a

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.