|
-
Sep 29th, 2003, 02:57 PM
#1
Thread Starter
Junior Member
Getting a reference to a client form Propertygrid
I have a custom control with properties I want displayed in the property grid. This has gone really well so far. I want to implement a property with a dropdown, listing all other controls on the client form. If I do the following;
<CategoryAttribute("Data Objects"), DefaultValueAttribute(""), _
DescriptionAttribute("Select a related control from the list")> _
Public Property ControlsOnForm() As String()
Get
Return _alCtrs
End Get
Set(ByVal Value As String())
_alCtrs = Value
End Set
End Property
Private Sub GetControlsOnForm()
Dim i As Int16 = 0
Dim alCtrs() As String
For Each ctr As Control In Me.ParentForm.Controls
ReDim Preserve alCtrs(i)
alCtrs(i) = ctr.Name
i += 1
Next
ControlsOnForm = alCtrs
End Sub
I get a String Collection Editor if I press the ellipse button. Is there a way I can change it so that I get a dropdown list instead?
Thanks
-
Sep 29th, 2003, 03:03 PM
#2
Since the property is of string type you get the string editor if you made it of control type or a specific control type then it should automatically be a dropdown of controls and/or specific controls on the form. At least that is how it does it for Usercontrols anyway.
-
Sep 29th, 2003, 05:33 PM
#3
Thread Starter
Junior Member
Thanks Edneeis for your reply. I have tried your suggestion and changed the type from string to control. I now get the control Collection editor. Still no dropdown.
Thanks
-
Sep 29th, 2003, 08:45 PM
#4
Thread Starter
Junior Member
Thanks all who tried to help me solve this problem. I have found a solution. By changing the property inside my user control from an array to a variable then using an internal class that inherits from the stringConverter to implement my dropdown
Public Shared _alCtrs() As String
Private Function GetControlsOnForm() As String()
Dim i As Int16 = 0
Dim alCtrs() As String
For Each ctr As Control In Me.ParentForm.Controls
ReDim Preserve alCtrs(i)
alCtrs(i) = ctr.Name
i += 1
Next
Return alCtrs
End Function
Private _ctr As String
<TypeConverter(GetType(ControlsConverter)), _
CategoryAttribute("Data Objects"), DefaultValueAttribute(""), _
DescriptionAttribute("Select a related control from the list")> _
Public Property ControlsOnForm() As String
Get
Return _ctr
End Get
Set(ByVal Value As String)
_ctr = Value
End Set
End Property
Private Class ControlsConverter : Inherits StringConverter
Public Overloads Overrides Function GetStandardValues(ByVal context As System.ComponentModel.ITypeDescriptorContext) As System.ComponentModel.TypeConverter.StandardValuesCollection
Return New StandardValuesCollection(_alCtrs)
End Function
'''
Public Overloads Overrides Function GetStandardValuesSupported(ByVal context As System.ComponentModel.ITypeDescriptorContext) As Boolean
Return True
End Function
'''
Public Overloads Overrides Function GetStandardValuesExclusive(ByVal context As System.ComponentModel.ITypeDescriptorContext) As Boolean
Return True
End Function
End Class
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|