Propertie grid control

  • Thread starter Thread starter Romain TAILLANDIER
  • Start date Start date
R

Romain TAILLANDIER

Hi Group

whne you are using VS.net, you have somewhere the properties windows, which
allow you to set some predefined value to your visual controls.

I develop some kind of editor, and i whish to have that kind of properties
screen.
Is there a classe to do this ?

Thanks
ROM
 
William,
VB.NET supports using attributes just like C#. Instead of square brackets []
you need to use angle brackets <>, it needs to be "on the same line" so
normally you give the line continuation character, lastly it if you list
multiple attributes they all need to be in one set of <> separated by
commas.

Imports System.ComponentModel

Public Class Class1

<Category("Behavior"), _
Description("This is the Special property")> _
Public Property Special() As String
...
End Class

Hope this helps
Jay
 
Jay:

I know that you can use attributes with VB.NET but I've come across a few
different posts where the [Description] attributes needed to create Groups
in the PropertyGrid were supposedly not available in VB.NET. I've tried
using Description in VB and could never get it to work ie

<Description("Any comment about this property."), Category("SomeCategory")>_
MyProperty

Have you been able to get it to work...if so, what am I doing wrong? I use
VB a lot and resorted to creating most of my UserControls in C# for this
simple reason, but I'd love to be able to do it in both languages.

Thanks,

Bill
Jay B. Harlow said:
William,
VB.NET supports using attributes just like C#. Instead of square brackets []
you need to use angle brackets <>, it needs to be "on the same line" so
normally you give the line continuation character, lastly it if you list
multiple attributes they all need to be in one set of <> separated by
commas.

Imports System.ComponentModel

Public Class Class1

<Category("Behavior"), _
Description("This is the Special property")> _
Public Property Special() As String
...
End Class

Hope this helps
Jay

William Ryan said:
Yes, it's the PropertyGrid control, you can check out some good articles on
how to use it here...
http://www.ftponline.com/vsm/2003_08/magazine/features/anderson/popup1.aspx
Be forewarned that you'll probably want ot use C# to do this though because
if you want to define Description Categories, I don't think you can do it
from VB.NEt.

HTH,

Bill
 
William,
I've never had it not work for me especially when I import the namespace
they are located in.

Do you perchance have an import for a different namespace that perchance
also has a DescriptionAttribute or CategoryAttribute in them, before the
System.ComponentModel import?

Remember there is a DescriptionAttribute class in both System.ComponentModel
& System.EnterpriseServices.

Hope this helps
Jay

William Ryan said:
Jay:

I know that you can use attributes with VB.NET but I've come across a few
different posts where the [Description] attributes needed to create Groups
in the PropertyGrid were supposedly not available in VB.NET. I've tried
using Description in VB and could never get it to work ie

<Description("Any comment about this property."), Category("SomeCategory")>_
MyProperty

Have you been able to get it to work...if so, what am I doing wrong? I use
VB a lot and resorted to creating most of my UserControls in C# for this
simple reason, but I'd love to be able to do it in both languages.

Thanks,

Bill
William,
VB.NET supports using attributes just like C#. Instead of square
brackets
[]
you need to use angle brackets <>, it needs to be "on the same line" so
normally you give the line continuation character, lastly it if you list
multiple attributes they all need to be in one set of <> separated by
commas.

Imports System.ComponentModel

Public Class Class1

<Category("Behavior"), _
Description("This is the Special property")> _
Public Property Special() As String
...
End Class

Hope this helps
Jay

William Ryan said:
Yes, it's the PropertyGrid control, you can check out some good
articles
on
how to use it here...
http://www.ftponline.com/vsm/2003_08/magazine/features/anderson/popup1.aspx
 
I know that you can use attributes with VB.NET but I've come across a few
different posts where the [Description] attributes needed to create Groups
in the PropertyGrid were supposedly not available in VB.NET. I've tried
using Description in VB and could never get it to work ie

<Description("Any comment about this property."), Category("SomeCategory")>_
MyProperty

Have you been able to get it to work...if so, what am I doing wrong? I use
VB a lot and resorted to creating most of my UserControls in C# for this
simple reason, but I'd love to be able to do it in both languages.

We use this for some of our classes, and it works just fine:

<System.ComponentModel.Description("Some description"), _
System.ComponentModel.Category("My category")> _
Public Property Fred() As MyEnum
...

Where I *do* have trouble is in creating such an attribute on a
property in a dynamically-created class. e.g.

Imports RE = System.Reflection.Emit
Imports SC = System.ComponentModel

Dim pb As RE.PropertyBuilder
' set up enough to be able to create pb here
Dim att as Type=GetType(SC.DescriptionAttribute)
Dim ci As ConstructorInfo = _
att.GetConstructor(New Type() {GetType(String)})
Dim cb As RE.CustomAttributeBuilder
cb = New RE.CustomAttributeBuilder(ci2, _
New Object() {"Test description"})
pb.SetCustomAttribute(cb)

I can see the attribute on the class, I can discover the description
from an instantiated object, but the PropertyGrid doesn't show the
description in the Help panel. Nor does equivalent code set the
Category such that the PropertyGrid uses it.
 
Back
Top