On Sat, 27 Nov 2004 00:08:37 -0500, David Gacek wrote:
Anyone know how to ... make a user control property that shows up in the
property pages and allows one to select a value from a set of values ?
like a combobox for example ?
If I understand correctly, you want a custom property that shows up in the
PropertyGrid as a drop down and you want to customize the list of available
choices.
In order to do this, create a class that inherits from StringConverter and
then override the GetStandardValues method to return an instance of a
StandardValuesCollection object with the correct values. Something similar
to this (watch for word wrap):
'CODE BEGINS HERE
Public Class MyCustomList
Inherits StringConverter
Public Overloads Overrides Function GetStandardValues(ByVal context As
System.ComponentModel.ITypeDescriptorContext) As
System.ComponentModel.TypeConverter.StandardValues Collection
Dim alMyList As New System.Collections.ArrayList
alMyList.Add("Item 1")
alMyList.Add("Item 2")
alMyList.Add("Item 3")
'Add other values to the array list here
Return New StandardValuesCollection(alMyList)
End Function
Public Overloads Overrides Function GetStandardValuesExclusive(ByVal
context As System.ComponentModel.ITypeDescriptorContext) As Boolean
Return True
End Function
Public Overloads Overrides Function GetStandardValuesSupported(ByVal
context As System.ComponentModel.ITypeDescriptorContext) As Boolean
Return True
End Function
End Class
'CODE ENDS HERE
Then to use it with your property, you need to add the TypeConverter
Attribute to your property:
Private m_MyItem As String
<TypeConverter(GetType(MyCustomList))> _
Public Property MyItem As String
Get
Return m_MyItem
End Get
Set(ByVal Value As String)
m_MyItem = Value
End Set
End Property
Hope this helps
--
Chris
dunawayc[AT]sbcglobal_lunchmeat_[DOT]net
To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.