How to put a clickable button on a PropertyGrid ?

G

Guest

I'm using the PropertyGrid control, and I want it to show a button.
But I set the PropertyGrid.SelectedObject with a object that as a Button
property, the PropertyGrid shows the buttons properties, and I want the
button to be shown as drawn and clickable button.

How can I do that?
 
M

Marc Gravell

IIRC, you can just do grid.Controls.Add(); [and be sure to bring your
control to the front afterwards]

Note that PropertyGrid.Controls doesn't show in the list, but it works just
fine. A better approach, however, may be to add a "tab"; these (bizarrely)
display as buttons; they are implemented differently, but give you more
control - simply inherit from PropertyTab and implement the necessary
methods (such as GetProperties if you want to filter the list).

Just type "PropertyTab Class" into MSDN2 (making sure you get
System.Windows.Forms.Design in 2.0) and you get a nice example. Note also
that the first tab seems to be always hidden, so you may need to add another
clone of PropertiesTab if you want to be able to swith back ;-p [just
subclass PropertiesTab and don't change anything (maybe the image) to
achieve this]

Marc
 
G

Guest

Thanks a lot for your help.
But I'm afraid that I did not explain my self as I should have.

When I implemented your suggestion, I got a button on the PropertyGrid frame
part on top, but I need the button to be shown on one of the cells at the
right column of the PropertyGrid.
I need the button to be shown instead of the value cell. The user should see
a clickable button that he'll be able to click on to perform some kind of
operation.

There may be some more buttons to be shown on another PropertyGrid cells.

Can you help me with that?
 
M

Marc Gravell

Oh, that!

You need to implement a UITypeEditor, which can provide either a popup or a
drop-down (both drawing whatever you want). If fixed drop-down (text) lists
and text editing / parsing are what you want, then you also need to look at
TypeConverter.

See MSDN: http://msdn2.microsoft.com/en-us/library/ms171840.aspx

(note that although you can support painting a preview in the grid, you
can't really put a button there until the user selects the drop-down; think
of the Dock /Anchor propertes for forms and you'll get the picture).

Note that this aspect of the component model can take some time to
understand, but it is very powerful.

Marc
 
C

cadilhac

Hello Sharon,

with the Microsoft PropertyGrid, there will be no way to have a button
that fills all the value cell space. If you want to look into
commercial product, this is something that Smart PropertyGrid.Net can
do by creating a custom inplace control. You can have a look at
http://www.visualhint.com

Best regards,

Nicolas Cadilhac
VisualHint - Home of Smart PropertyGrid.Net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top