Using the propertygrid.. can I bind it to a class object

G

Guest

Hi,

I am looking at the propertygrid as its a perfect fit for what I want. The
problem is it only seems to be able to be 'connected' to toolbox object I
have put on the form.. such as a textbox or combobox.

I have a class that I have created that. Its basiclly a class that
represents a person (name, age, etc) so the property grid would be great to
capture this sort of data.

Is there a way to connect the propertygrid to my class ?

If not does anybody know of a vendor that creates a low cost property grid
that I could use. I have take a look around and don't see anything....

Thanks!
 
T

Tom Shelton

Hi,

I am looking at the propertygrid as its a perfect fit for what I want. The
problem is it only seems to be able to be 'connected' to toolbox object I
have put on the form.. such as a textbox or combobox.

I have a class that I have created that. Its basiclly a class that
represents a person (name, age, etc) so the property grid would be great to
capture this sort of data.

Is there a way to connect the propertygrid to my class ?

If not does anybody know of a vendor that creates a low cost property grid
that I could use. I have take a look around and don't see anything....

Thanks!

The propertyGrid has a .SelectedObject property. That's how you connect an
instance of an object to the propertygrid. It has a bunch of events to tell
you if a value has changed. Not only that there are attributes that can be
used to assing categories, default values, and visibiltiy to the grid.
 
T

Tom Shelton

Hi,

I am looking at the propertygrid as its a perfect fit for what I want. The
problem is it only seems to be able to be 'connected' to toolbox object I
have put on the form.. such as a textbox or combobox.

I have a class that I have created that. Its basiclly a class that
represents a person (name, age, etc) so the property grid would be great to
capture this sort of data.

Is there a way to connect the propertygrid to my class ?

If not does anybody know of a vendor that creates a low cost property grid
that I could use. I have take a look around and don't see anything....

Thanks!

You know... I decided that I probably better put together a quick and dirty
example... So, here you go. A form with a property grid docked to fill:

Our class:

Option Explicit On
Option Strict On

Imports System.ComponentModel

Friend Class Customer
Private _id As Integer
Private _name As String
Private _password As String

<Browsable(True), Category("DB Stuff"), Description("If I have to tell you...")> _
Public Property Id() As Integer
Get
Return _id
End Get
Set(ByVal value As Integer)
_id = value
End Set
End Property

<Browsable(True), Category("The Name Category"), Description("This cod fish's name!")> _
Public Property Name() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property

<Browsable(False)> _
Public Property Password() As String
Get
Return _password
End Get
Set(ByVal value As String)
_password = value
End Set
End Property
End Class

The form:

Option Explicit On
Option Strict On


Public Class Form1
Private customer As New Customer


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PropertyGrid1.SelectedObject = customer
End Sub

Private Sub PropertyGrid1_PropertyValueChanged(ByVal s As System.Object, ByVal e As System.Windows.Forms.PropertyValueChangedEventArgs) Handles PropertyGrid1.PropertyValueChanged
MessageBox.Show(String.Format("{0} changed from {1} to {2}", e.ChangedItem.PropertyDescriptor.Name, e.OldValue, e.ChangedItem.Value))
End Sub
End Class


HTH
 
G

Guest

Excellent... thank you..

Just what I needed, and it does exactly what I want...

Again.. thanks!!
 

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