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.