65.9K
CodeProject is changing. Read more.
Home

Bending .NET PropertyGrid to your will with a Custom Type Editor

starIconstarIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIcon

2.41/5 (14 votes)

Jan 13, 2004

viewsIcon

119040

downloadIcon

951

Example of using the propertybag class of Tony Allowatt in vb.net with a custom type editor

Sample Image - Propertygrid_Editor_demo.jpg

Introduction

I've had serious trouble doing these two things:

  • Using a propertygrid and having all of its properties (like the names of the properties, and description that is shown) dynamic, in VB.NET
  • Using Tony Allowat's classes (which solves the first problem) with a custom type editor

I finally managed to get things working ... and thought that others amongst you could be having the same problem as I ... So here it is, my working VB.NET version of Tony Allowatt's propertybag classes, implementing a custom type editor.

Background

I didn't write the code of the PropertyBag.vb file ... Tony Allowatt wrote these usefull classes for the propertygrid, but in C#. Read his article first! Bending the .NET PropertyGrid to Your Will

Using the code

I'm not going to explain much in here, as all the serious code has been explained by Tony Allowatt in his article. I only provide an example of how to use his classes with a custom editor.

Public Class MyOwnClass
 ' the class that will be shown in the propertygrid
 ' it has a property of typ MultiLineString
End Class 

Public Class MultiLineString
 ' this is the custom type we'll want to edit in the propertygrid
 ' it's just a class with 1 property, a string, but 
 ' we want a multiline editor for it

 ' ...
End Class

Public Class MultiLineStringEditor
 Inherits UITypeEditor
 ' ...
End Class

Public Class MultiLineStringConverter
 Inherits System.ComponentModel.TypeConverter
 ' ...
End Class

Public Class MultiLineStringEditorForm
 Inherits System.Windows.Forms.Form
 ' ...
End Class

Points of interest

Some interesting links:

History

  • 14-01-2004 - Initial Release
Bending .NET PropertyGrid to your will with a Custom Type Editor - CodeProject