Question CheckedListBox in PropGrid

jackgreat

Active member
Joined
Apr 17, 2006
Messages
35
Programming Experience
1-3
Hi Guys,

I am using a propertygrid in vb.net (2008). I am able to populate it and save & get its values. So far so good.

I wanted to know how can I impliment a checked list box in propertygrid. (Shown in Image). Basically i have for example - first name, middle name and last name in property grid. I want to ask him which one he want to show or all. So in this way (checkedlistbox) he can select which one or all. To achieve something like this I guess a checkedlistbox need to be there in propgrid.


Will be glad if anyone can tell me how to do that?

Thanks,

Cheers,
JG
 

Attachments

  • propgrid.jpg
    propgrid.jpg
    87.7 KB · Views: 62
Post a sample code for how you'd do this (the above Options property for example) with PropertyBag and I'll review it.
 
code

Posting sample code.

Code for PropertyBag class

VB.NET:
Imports System
Imports System.Collections
Imports System.ComponentModel

Public Class PropertySpec
    Private m_attributes As Attribute()
    Private m_category As String
    Private m_defaultValue As Object
    Private m_description As String
    Private editor As String
    Private m_name As String
    Private type As String
    Private typeConverter As String

    Public Sub New(ByVal name As String, ByVal type As String)
        Me.New(name, type, Nothing, Nothing, Nothing)
    End Sub

    Public Sub New(ByVal name As String, ByVal type As Type)
        Me.New(name, type.AssemblyQualifiedName, Nothing, Nothing, Nothing)
    End Sub

    Public Sub New(ByVal name As String, ByVal type As String, ByVal category As String)
        Me.New(name, type, category, Nothing, Nothing)
    End Sub

    Public Sub New(ByVal name As String, ByVal type As Type, ByVal category As String)
        Me.New(name, type.AssemblyQualifiedName, category, Nothing, Nothing)
    End Sub

    Public Sub New(ByVal name As String, ByVal type As String, ByVal category As String, ByVal description As String)
        Me.New(name, type, category, description, Nothing)
    End Sub

    Public Sub New(ByVal name As String, ByVal type As Type, ByVal category As String, ByVal description As String)
        Me.New(name, type.AssemblyQualifiedName, category, description, Nothing)
    End Sub

    Public Sub New(ByVal name As String, ByVal type As String, ByVal category As String, ByVal description As String, ByVal defaultValue As Object)
        Me.m_name = name
        Me.type = type
        Me.m_category = category
        Me.m_description = description
        Me.m_defaultValue = defaultValue
        Me.m_attributes = Nothing
    End Sub

    Public Sub New(ByVal name As String, ByVal type As Type, ByVal category As String, ByVal description As String, ByVal defaultValue As Object)
        Me.New(name, type.AssemblyQualifiedName, category, description, defaultValue)
    End Sub

    Public Sub New(ByVal name As String, ByVal type As String, ByVal category As String, ByVal description As String, ByVal defaultValue As Object, ByVal editor As String, _
    ByVal typeConverter As String)
        Me.New(name, type, category, description, defaultValue)
        Me.editor = editor
        Me.typeConverter = typeConverter
    End Sub

    Public Sub New(ByVal name As String, ByVal type As Type, ByVal category As String, ByVal description As String, ByVal defaultValue As Object, ByVal editor As String, _
    ByVal typeConverter As String)
        Me.New(name, type.AssemblyQualifiedName, category, description, defaultValue, editor, _
        typeConverter)
    End Sub

    Public Sub New(ByVal name As String, ByVal type As String, ByVal category As String, ByVal description As String, ByVal defaultValue As Object, ByVal editor As Type, _
    ByVal typeConverter As String)
        Me.New(name, type, category, description, defaultValue, editor.AssemblyQualifiedName, _
        typeConverter)
    End Sub

    Public Sub New(ByVal name As String, ByVal type As Type, ByVal category As String, ByVal description As String, ByVal defaultValue As Object, ByVal editor As Type, _
    ByVal typeConverter As String)
        Me.New(name, type.AssemblyQualifiedName, category, description, defaultValue, editor.AssemblyQualifiedName, _
        typeConverter)
    End Sub

   
    Public Sub New(ByVal name As String, ByVal type As String, ByVal category As String, ByVal description As String, ByVal defaultValue As Object, ByVal editor As String, _
    ByVal typeConverter As Type)
        Me.New(name, type, category, description, defaultValue, editor, _
        typeConverter.AssemblyQualifiedName)
    End Sub

    Public Sub New(ByVal name As String, ByVal type As Type, ByVal category As String, ByVal description As String, ByVal defaultValue As Object, ByVal editor As String, _
    ByVal typeConverter As Type)
        Me.New(name, type.AssemblyQualifiedName, category, description, defaultValue, editor, _
        typeConverter.AssemblyQualifiedName)
    End Sub

    
    Public Sub New(ByVal name As String, ByVal type As String, ByVal category As String, ByVal description As String, ByVal defaultValue As Object, ByVal editor As Type, _
    ByVal typeConverter As Type)
        Me.New(name, type, category, description, defaultValue, editor.AssemblyQualifiedName, _
        typeConverter.AssemblyQualifiedName)
    End Sub

    Public Sub New(ByVal name As String, ByVal type As Type, ByVal category As String, ByVal description As String, ByVal defaultValue As Object, ByVal editor As Type, _
    ByVal typeConverter As Type)
        Me.New(name, type.AssemblyQualifiedName, category, description, defaultValue, editor.AssemblyQualifiedName, _
        typeConverter.AssemblyQualifiedName)
    End Sub

    Public Property Attributes() As Attribute()
        Get
            Return m_attributes
        End Get
        Set(ByVal value As Attribute())
            m_attributes = value
        End Set
    End Property

    Public Property Category() As String
        Get
            Return m_category
        End Get
        Set(ByVal value As String)
            m_category = value
        End Set
    End Property

    Public Property ConverterTypeName() As String
        Get
            Return typeConverter
        End Get
        Set(ByVal value As String)
            typeConverter = value
        End Set
    End Property

    Public Property DefaultValue() As Object
        Get
            Return m_defaultValue
        End Get
        Set(ByVal value As Object)
            m_defaultValue = value
        End Set
    End Property

    Public Property Description() As String
        Get
            Return m_description
        End Get
        Set(ByVal value As String)
            m_description = value
        End Set
    End Property

    Public Property EditorTypeName() As String
        Get
            Return editor
        End Get
        Set(ByVal value As String)
            editor = value
        End Set
    End Property

    Public Property Name() As String
        Get
            Return m_name
        End Get
        Set(ByVal value As String)
            m_name = value
        End Set
    End Property

    Public Property TypeName() As String
        Get
            Return type
        End Get
        Set(ByVal value As String)
            type = value
        End Set
    End Property
End Class


Public Class PropertySpecEventArgs
    Inherits EventArgs
    Private m_property As PropertySpec
    Private val As Object

    Public Sub New(ByVal [property] As PropertySpec, ByVal val As Object)
        Me.m_property = [property]
        Me.val = val
    End Sub

    Public ReadOnly Property [Property]() As PropertySpec
        Get
            Return m_property
        End Get
    End Property

    Public Property Value() As Object
        Get
            Return val
        End Get
        Set(ByVal value As Object)
            val = value
        End Set
    End Property
End Class


Public Delegate Sub PropertySpecEventHandler(ByVal sender As Object, ByVal e As PropertySpecEventArgs)


Public Class PropertyBag
    Implements ICustomTypeDescriptor
#Region "PropertySpecCollection class definition"
  
    <Serializable()> _
    Public Class PropertySpecCollection

        Private innerArray As ArrayList

       
        Public Sub New()
            innerArray = New ArrayList()
        End Sub

        Public ReadOnly Property Count() As Integer
            Get
                Return innerArray.Count
            End Get
        End Property

        Public ReadOnly Property IsFixedSize() As Boolean
            Get
                Return False
            End Get
        End Property

        Public ReadOnly Property IsReadOnly() As Boolean
            Get
                Return False
            End Get
        End Property

      

        Public ReadOnly Property IsSynchronized() As Boolean
            Get
                Return False
            End Get
        End Property

       
        Private ReadOnly Property SyncRoot() As Object
            Get
                Return Nothing
            End Get
        End Property


        Public Function Add(ByVal value As PropertySpec) As Integer
            Dim index As Integer = innerArray.Add(value)

            Return index
        End Function

        Public Sub AddRange(ByVal array As PropertySpec())
            innerArray.AddRange(array)
        End Sub

       
        Public Sub Clear()
            innerArray.Clear()
        End Sub

        Public Function Contains(ByVal item As PropertySpec) As Boolean
            Return innerArray.Contains(item)
        End Function

      
        Public Function Contains(ByVal name As String) As Boolean
            For Each spec As PropertySpec In innerArray
                If spec.Name = name Then
                    Return True
                End If
            Next

            Return False
        End Function

        Public Sub CopyTo(ByVal array As PropertySpec())
            innerArray.CopyTo(array)
        End Sub

        Public Sub CopyTo(ByVal array As PropertySpec(), ByVal index As Integer)
            innerArray.CopyTo(array, index)
        End Sub

        Public Function GetEnumerator() As IEnumerator
            Return innerArray.GetEnumerator()
        End Function

  
        Public Function IndexOf(ByVal value As PropertySpec) As Integer
            Return innerArray.IndexOf(value)
        End Function

     
        Public Function IndexOf(ByVal name As String) As Integer
            Dim i As Integer = 0

            For Each spec As PropertySpec In innerArray
                If spec.Name = name Then
                    Return i
                End If

                i += 1
            Next

            Return -1
        End Function

       
        Public Sub Insert(ByVal index As Integer, ByVal value As PropertySpec)
            innerArray.Insert(index, value)
        End Sub

        Public Sub Remove(ByVal obj As PropertySpec)
            innerArray.Remove(obj)
        End Sub

    
        Public Sub Remove(ByVal name As String)
            Dim index As Integer = IndexOf(name)
            RemoveAt(index)
        End Sub

       
        Public Sub RemoveAt(ByVal index As Integer)
            innerArray.RemoveAt(index)
        End Sub

        Public Function ToArray() As PropertySpec()
            Return DirectCast(innerArray.ToArray(GetType(PropertySpec)), PropertySpec())
        End Function


       



      

    End Class
#End Region

#Region "PropertySpecDescriptor class definition"
    Private Class PropertySpecDescriptor
        Inherits PropertyDescriptor
        Private bag As PropertyBag
        Private item As PropertySpec

        Public Sub New(ByVal item As PropertySpec, ByVal bag As PropertyBag, ByVal name As String, ByVal attrs As Attribute())
            MyBase.New(name, attrs)
            Me.bag = bag
            Me.item = item
        End Sub

        Public Overloads Overrides ReadOnly Property ComponentType() As Type
            Get
                Return item.[GetType]()
            End Get
        End Property

        Public Overloads Overrides ReadOnly Property IsReadOnly() As Boolean
            Get
                Return (Attributes.Matches(ReadOnlyAttribute.Yes))
            End Get
        End Property

        Public Overloads Overrides ReadOnly Property PropertyType() As Type
            Get
                Return Type.[GetType](item.TypeName)
            End Get
        End Property

        Public Overloads Overrides Function CanResetValue(ByVal component As Object) As Boolean
            If item.DefaultValue Is Nothing Then
                Return False
            Else
                Return Not Me.GetValue(component).Equals(item.DefaultValue)
            End If
        End Function

        Public Overloads Overrides Function GetValue(ByVal component As Object) As Object
          
            Dim e As New PropertySpecEventArgs(item, Nothing)
            bag.OnGetValue(e)
            Return e.Value
        End Function

        Public Overloads Overrides Sub ResetValue(ByVal component As Object)
            SetValue(component, item.DefaultValue)
        End Sub

        Public Overloads Overrides Sub SetValue(ByVal component As Object, ByVal value As Object)
          
            Dim e As New PropertySpecEventArgs(item, value)
            bag.OnSetValue(e)
        End Sub

        Public Overloads Overrides Function ShouldSerializeValue(ByVal component As Object) As Boolean
            Dim val As Object = Me.GetValue(component)

            If item.DefaultValue Is Nothing AndAlso val Is Nothing Then
                Return False
            Else
                Return Not val.Equals(item.DefaultValue)
            End If
        End Function
    End Class
#End Region

    Private m_defaultProperty As String
    Private m_properties As PropertySpecCollection

    Public Sub New()
        m_defaultProperty = Nothing
        m_properties = New PropertySpecCollection()
    End Sub

  
    Public Property DefaultProperty() As String
        Get
            Return m_defaultProperty
        End Get
        Set(ByVal value As String)
            m_defaultProperty = value
        End Set
    End Property

    Public ReadOnly Property Properties() As PropertySpecCollection
        Get
            Return m_properties
        End Get
    End Property

    Public Event GetValue As PropertySpecEventHandler

    Public Event SetValue As PropertySpecEventHandler

    Protected Overridable Sub OnGetValue(ByVal e As PropertySpecEventArgs)
        RaiseEvent GetValue(Me, e)
    End Sub

    Protected Overridable Sub OnSetValue(ByVal e As PropertySpecEventArgs)
        RaiseEvent SetValue(Me, e)
    End Sub

    Private Function GetAttributes() As AttributeCollection Implements ICustomTypeDescriptor.GetAttributes
        Return TypeDescriptor.GetAttributes(Me, True)
    End Function

    Private Function GetClassName() As String Implements ICustomTypeDescriptor.GetClassName
        Return TypeDescriptor.GetClassName(Me, True)
    End Function

    Private Function GetComponentName() As String Implements ICustomTypeDescriptor.GetComponentName
        Return TypeDescriptor.GetComponentName(Me, True)
    End Function

    Private Function GetConverter() As TypeConverter Implements ICustomTypeDescriptor.GetConverter
        Return TypeDescriptor.GetConverter(Me, True)
    End Function

    Private Function GetDefaultEvent() As EventDescriptor Implements ICustomTypeDescriptor.GetDefaultEvent
        Return TypeDescriptor.GetDefaultEvent(Me, True)
    End Function

    Private Function GetDefaultProperty() As PropertyDescriptor Implements ICustomTypeDescriptor.GetDefaultProperty

        Dim propertySpec As PropertySpec = Nothing
        If m_defaultProperty IsNot Nothing Then
            Dim index As Integer = m_properties.IndexOf(m_defaultProperty)
            ' propertySpec = m_properties(index)
        End If

        If propertySpec IsNot Nothing Then
            Return New PropertySpecDescriptor(propertySpec, Me, propertySpec.Name, Nothing)
        Else
            Return Nothing
        End If
    End Function

    Private Function GetEditor(ByVal editorBaseType As Type) As Object Implements ICustomTypeDescriptor.GetEditor
        Return TypeDescriptor.GetEditor(Me, editorBaseType, True)
    End Function

    Private Function GetEvents() As EventDescriptorCollection Implements ICustomTypeDescriptor.GetEvents
        Return TypeDescriptor.GetEvents(Me, True)
    End Function

    Private Function GetEvents(ByVal attributes As Attribute()) As EventDescriptorCollection Implements ICustomTypeDescriptor.GetEvents
        Return TypeDescriptor.GetEvents(Me, attributes, True)
    End Function

    Private Function GetProperties() As PropertyDescriptorCollection Implements ICustomTypeDescriptor.GetProperties
        Return DirectCast(Me, ICustomTypeDescriptor).GetProperties(New Attribute(-1) {})
    End Function

    Private Function GetProperties(ByVal attributes As Attribute()) As PropertyDescriptorCollection Implements ICustomTypeDescriptor.GetProperties

        Dim props As New ArrayList()

        For Each [property] As PropertySpec In m_properties
            Dim attrs As New ArrayList()

            If [property].Category IsNot Nothing Then
                attrs.Add(New CategoryAttribute([property].Category))
            End If

            If [property].Description IsNot Nothing Then
                attrs.Add(New DescriptionAttribute([property].Description))
            End If

            If [property].ConverterTypeName IsNot Nothing Then
                attrs.Add(New TypeConverterAttribute([property].ConverterTypeName))
            End If

            If [property].Attributes IsNot Nothing Then
                attrs.AddRange([property].Attributes)
            End If

            Dim attrArray As Attribute() = DirectCast(attrs.ToArray(GetType(Attribute)), Attribute())

        
            Dim pd As New PropertySpecDescriptor([property], Me, [property].Name, attrArray)
            props.Add(pd)
        Next

        Dim propArray As PropertyDescriptor() = DirectCast(props.ToArray(GetType(PropertyDescriptor)), PropertyDescriptor())
        Return New PropertyDescriptorCollection(propArray)
    End Function

    Private Function GetPropertyOwner(ByVal pd As PropertyDescriptor) As Object Implements ICustomTypeDescriptor.GetPropertyOwner
        Return Me
    End Function
End Class


Public Class PropertyTable
    Inherits PropertyBag
    Private propValues As Hashtable

    
    Public Sub New()
        propValues = New Hashtable()
    End Sub

   
    Default Public Property Item(ByVal key As String) As Object
        Get
            Return propValues(key)
        End Get
        Set(ByVal value As Object)
            propValues(key) = value
        End Set
    End Property

  
    Protected Overloads Overrides Sub OnGetValue(ByVal e As PropertySpecEventArgs)
        e.Value = propValues(e.[Property].Name)
        MyBase.OnGetValue(e)
    End Sub

    Protected Overloads Overrides Sub OnSetValue(ByVal e As PropertySpecEventArgs)
        propValues(e.[Property].Name) = e.Value
        MyBase.OnSetValue(e)
    End Sub
End Class

Sample Code as to How would I call

VB.NET:
Imports System.Windows.Forms.Design
Imports System.Drawing.Design
Imports System.ComponentModel

Public Class Form1
    Dim P As PropertyBag
    Dim options As New Dictionary(Of String, Boolean)

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        options.Add("A", True)
        options.Add("B", False)
        options.Add("C", False)

        P = New PropertyBag

        P.Properties.Add(New PropertySpec("Name", "System.String", "C", "D"))
        P.Properties.Add(New PropertySpec("Choose", options.GetType, "C", "D", Nothing, GetType(OptionsEditor), ""))

        PropertyGrid1.SelectedObject = P

        AddHandler P.GetValue, AddressOf Me.P_GetValue

    End Sub
End Class

Public Class OptionsEditor
    Inherits UITypeEditor

    Public Overrides Function GetEditStyle(ByVal context As ITypeDescriptorContext) As UITypeEditorEditStyle
        Return UITypeEditorEditStyle.DropDown
    End Function

    Public Overloads Overrides Function EditValue(ByVal context As ITypeDescriptorContext, ByVal provider As IServiceProvider, ByVal value As Object) As Object
        '       Check if the required objects exist
        If context Is Nothing OrElse context.Instance Is Nothing OrElse provider Is Nothing Then Return value
        Dim editorService As IWindowsFormsEditorService = CType(provider.GetService(GetType(IWindowsFormsEditorService)), IWindowsFormsEditorService)
        If editorService Is Nothing Then Return value
        '      create the checklist
        Dim chkList As New CheckedListBox
        Dim options As Dictionary(Of String, Boolean) = CType(value, Dictionary(Of String, Boolean))
        For Each key As String In options.Keys
            chkList.Items.Add(key, options(key))
        Next
        With chkList
            .BorderStyle = BorderStyle.None
            .CheckOnClick = True
            If .Height > (.Items.Count * .ItemHeight) Then
                '              Adjust the height of the list
                .Height = .Items.Count * .ItemHeight
            End If
        End With
        '     Display the drop down list
        editorService.DropDownControl(chkList)

        '   get checked states
        For i As Integer = 0 To chkList.Items.Count - 1
            Dim key As String = CStr(chkList.Items(i))
            options(key) = chkList.GetItemChecked(i)
        Next
        chkList.Dispose()

        Return value
    End Function
End Class

Please check and give me a code sample that would do the trick. I didnt know this issue would take so long and I would still be struggling.

Thanks for your help John. :)
 
AddHandler P.GetValue, AddressOf Me.P_GetValue
Can you post your P_GetValue event handler method also?
You also need to Add a Handler for P SetValue event, post your attempt at this also.

If you refer to article that explains these methods:
Method 1: Raising Events

The method implemented by the base PropertyBag class raises events whenever property values are queried or changed. The GetValue event occurs when the property grid needs to know the value of a certain property, and SetValue occurs when the user has interactively changed the value of the property in the grid.

This method is useful in situations dealing with properties that are stored in files and databases. When the event occurs, you can use the property name to index into the data source, using the same simple lookup code for every property.

Method 2: Storing the Values in a Table

For a simpler approach that might be more appropriate in some cases, I've derived a class from PropertyBag called PropertyTable. This class provides all the generic functionality of PropertyBag but also contains a hashtable, indexed by property name, to store property values. When a value is requested, the property is looked up in the table, and when the user updates it, the value in the hashtable is updated accordingly.
"Method 2" is the one I gave you a working sample for in case you didn't notice.

More about the functionality of the events for "Method 1" from article:
The GetValue event is raised whenever the property grid needs to request the value of a property. This can happen for several reasons, such as displaying the property, comparing it to the default value to determine if it can be reset, among others.

The SetValue event is raised whenever the user modifies the value of the property through the grid.
The "value" for your Choose property is the Options dictionary.
 
I am aware of GetValue and SetValue property and have used it before. As I mentioned that before encountering the problem of checkedlistbox I was using propertygrid whereby i could save & load values like integer, colour, stirng.

I forgot to write the handler in this post. I guess I wrote this -

VB.NET:
AddHandler P.GetValue, AddressOf Me.PropGrid_GetValue
AddHandler P.SetValue, AddressOf Me.PropGrid_SetValue

    Private Sub PropGrid_GetValue(ByVal sender As Object, ByVal e As PropertySpecEventArgs)

   Select Case e.[Property].Name
      case "Choose" 
        e.value = options '  name of dict obj
End Sub

' Similar for set value

Dude, the thing is, I need to get the checkedlistbox to work. Please give me a code that is able to call editvalue and that works by showing what we want. Even if there is an error in GetValue, you can let me know and fix the class and give me a working code.

Set is only called if a value is changed and not while its being changed.

I hope to get a final code from you which shows us the checkedlistbox for an item. Thanks.
 
Your PropertyBag classes is not correctly converted, which I couldn't see until I reviewed your complete code from last two posts. When I tested the codes earlier I just referenced the original classes as a class library assembly (compiled from C#). You can do the same, or you can use the converted classes I have attached (unzip and add the file with "Add existing.." to project), these were converted with an online conversion tool and total accuracy is not guaranteed, I just fixed the immediate compile errors and do not feel like proof-reading them, using these classes instead did however work properly for the both property samples I have posted here (flags enum and dictionary), both with "method 1" and "method 2".
I hope to get a final code from you which shows us the checkedlistbox for an item
All my previous samples and suggestions have been final and fully functional btw.
 

Attachments

  • PropertyBag.zip
    6.1 KB · Views: 33
Thanks a ton

Thanks a lot for your help John.:) The code worked, the propertybag code you fixed along with the editor code did the job.

Thanks again for helping me out for last few days. I know just the words thanks is not enough to express my gratitude but I really appreciate what you have done.

Phew, all is working fine so far. The word Collection appears as a text on that field. Can it be changed ?

(For info purposes can a boolean value be represented as a checkbox in property grid. In other words, can a single checkbox appear in propertygrid)
 
Last edited:
Phew, all is working fine so far. The word Collection appears as a text on that field. Can it be changed ?
Write a custom TypeConverter that inherits the default CollectionConverter, return the custom text in ConvertTo for String type, like this:
VB.NET:
Public Class CustomCollectionConverter
    Inherits CollectionConverter

    Public Overrides Function ConvertTo(ByVal context As ITypeDescriptorContext, ByVal culture As System.Globalization.CultureInfo, _
    ByVal value As Object, ByVal destinationType As System.Type) As Object
        If destinationType Is GetType(String) Then
            Return "custom display text"
        End If
        Return MyBase.ConvertTo(context, culture, value, destinationType)
    End Function
End Class
In this case the display text does not represent the value and be used for any display purpose. Tell the PropertySpec to use this converter:
VB.NET:
New PropertySpec("Options",......, GetType(CustomCollectionConverter))
 
For info purposes can a boolean value be represented as a checkbox in property grid. In other words, can a single checkbox appear in propertygrid
As dropdown, yes, just write a UITypeEditor for it. In the value part of grid where normally only strings display there is only room for a small image, this is done with a UITypeEditor where GetPaintValueSupported must return True and PaintValue is where you draw the image, this image can be a checkbox that display the checked value, but it will not be a fully functional one-click checkbox control, but you can doubleclick the image same as the value text to toggle the checked state. Here is an example of such an editor:
VB.NET:
Public Class CheckBoxEditor
    Inherits Drawing.Design.UITypeEditor

    Public Overloads Overrides Function GetPaintValueSupported(ByVal context As ITypeDescriptorContext) As Boolean
        Return True
    End Function

    Public Overloads Overrides Sub PaintValue(ByVal e As Drawing.Design.PaintValueEventArgs)
        If CType(e.Value, Boolean) Then
            ControlPaint.DrawCheckBox(e.Graphics, e.Bounds, ButtonState.Checked)
        Else
            ControlPaint.DrawCheckBox(e.Graphics, e.Bounds, ButtonState.Normal)
        End If
    End Sub

End Class
and the property spec ;)
VB.NET:
New PropertySpec("Check", GetType(Boolean), ........, GetType(CheckBoxEditor), "")
I think you will find this article interesting for more in depth coverage of the PropertyGrid and things: Getting the Most Out of the .NET Framework PropertyGrid Control
 
Thank You

The code for changing text of customcollection worked. I guess all my questions have been answered.

Thank you very much for answering all my queries. :)

You have been very supportive and its your help only that has enabled me to do what I was intending to do.

I am not good with words but If there is anything I can do for your please let me know.

Thanks again...
 
Dropdown List in PropertyGrid

Hi Guys,

I have used propertygrid before and I found a code in codeproject called PropertyBag which enables easy dynamic adding of properties to propertygrid.

Here is the link: CodeProject: Bending the .NET PropertyGrid to Your Will. Free source code and programming help

Now what I want is a simple dropdown list of few hardcoded values. I know this is easy to implement and can be done using Enum. But the problem is I want space also for example: "Jack Dawson" "Bill Hill" etc this way I want a dropdown and enum does not support spaces.

How can I implement this in propertygrid ?

Help will be appreciated.

Thanks,
Jack
 
Since this was so closely related to your previous thread and specialized to this custom property class I decided merge them.

Should these option be the only valid values or only suggestions? For the latter you can you do as explained in article I linked (see "Adding Domain List and Simple Drop-down Property Support"), for the former you can add description attributes to the enum values and rework the enum editor to display these.
 
Since this was so closely related to your previous thread and specialized to this custom property class I decided merge them.

Should these option be the only valid values or only suggestions? For the latter you can you do as explained in article I linked (see "Adding Domain List and Simple Drop-down Property Support"), for the former you can add description attributes to the enum values and rework the enum editor to display these.

Thanks for your reply john. The values which I stated were suggestions only. But what I want to indicate is that I will be adding around 10-12 values and some of them will be 2 words with a space between them. These values would not be added dynamically and they will be fixed.

- Adding Domain List and Simple Drop-down Property Support. Did not find any attachment. But I saw a similar article in msdn and tried to bind it with propertybag but was not successful.

-Add description attributes to the enum values and rework the enum editor to display these. - How do I do that? Just need to rework this and bind it with propertybag.

Need some help in this. I tried using several methods with prop bag but am not getting desired result. In one instance i tried msdn code for drop down and i could see dropdown but couldnt select and set. I mean I am still stuck.
 
Well I mentioned that I have already seen this article before. I was not able to merge it with my propertybag. Thats where I got stuck.
 
Back
Top