954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

PropertyGird.SelectedObjects Help

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

KillerOfDN
Junior Poster in Training
51 posts since Apr 2008
Reputation Points: 3
Solved Threads: 1
 

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.

ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
 
Object[] myObjs = new Object[1];


should be

Object[] myObjs = new Object[2];


or even

PropertyGrid1.SelectedObjects = new object [] { new A(), new B() };
Blorgle
Newbie Poster
1 post since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You