Hello all,
here is my problem. I am using a property grid control (in a vb.net 2003
project) in which two properties are exposed : "editorStyle" and "events".
The first property is used to select one of a series of web controls. The
second one opens a collectioneditor which also exposes two properties :
"event" and "command". The "event" property is a combobox that is filled with
the events of the control that was selected in the "editorStyle" property
(so, if we select a label, the label's events are used to fill the "event"
property; if a button is selected , the button's events are used to fill the
"event" property ,etc. ). The "command" property is clear text.
To achieve that i have come up with the following code (by moving parts from
internet downloaded code)
Public Class colProperties
'type of editor
Public Enum editorStyleEnum
es_label = 1
es_textbox = 2
es_bound_dropdownlist = 3
es_bound_checkboxlist = 5
es_bound_radiobuttonlist = 7
End Enum
Private y As ControlEvents
Private _editorStyle As editorStyleEnum
Public Property editorStyle() As editorStyleEnum
Get
editorStyle = _editorStyle
columnType = _editorStyle
End Get
Set(ByVal Value As editorStyleEnum)
_editorStyle = Value
End Set
End Property
<Editor("CollectionEditor", "UITypeEditor")> _
Public Property events() As ControlEvents
Get
events = y
End Get
Set(ByVal Value As ControlEvents)
y = Value
End Set
End Property
End Class
'this is the class, the properties of which are exposed in the
collectionEditor
Public Class ControlEvent
Private _command As String
Private _event As Object
<TypeConverter(GetType(EventConverter))> _
Public Property eventNames() As String
Get
eventNames = _event
End Get
Set(ByVal Value As String)
_event = Value
End Set
End Property
Public Property command() As String
Get
Return Me._command
End Get
Set(ByVal Value As String)
Me._command = Value
End Set
End Property
Public Sub New()
Me._command = ""
End Sub
End Class
'this is the class of a collection of controlEvent objects
Public Class ControlEvents
Inherits CollectionBase
'Retrieves an item from the collection by index
Default Public Property Item(ByVal Index As Integer) As ControlEvent
Get
Return CType(list.Item(Index), ControlEvent)
End Get
Set(ByVal Value As ControlEvent)
list.Item(Index) = Value
End Set
End Property
'Adds an item to the collection
Public Function Add(ByVal Item As ControlEvent) As Integer
Return list.Add(Item)
End Function
Public Sub Remove(ByVal Item As ControlEvent)
list.Remove(Item)
End Sub
End Class
'this class is used to fill the "event" property of the collectionEditor
'using the <TypeConverter(GetType(EventConverter))> attribute
Friend Class EventConverter
Inherits StringConverter
Private Shared events As StandardValuesCollection
Public Sub New()
Try
Dim myTypeEvent As Type
Dim i As Int16, eventNames As String()
Select Case columnType 'this is declared in a module (as public)
Case 1
myTypeEvent = GetType(System.Windows.Forms.Label)
Case 2
myTypeEvent = GetType(System.Windows.Forms.TextBox)
Case 3
myTypeEvent = GetType(System.Windows.Forms.ComboBox)
Case 5
myTypeEvent = GetType(System.Windows.Forms.CheckBox)
Case 7
myTypeEvent = GetType(System.Windows.Forms.RadioButton)
End Select
Dim events_info As System.Reflection.EventInfo() =
myTypeEvent.GetEvents
ReDim Preserve eventNames(events_info.Length - 1)
For i = 0 To events_info.Length - 1
eventNames(i) = events_info(i).Name
Next
events = New StandardValuesCollection(eventNames)
Catch ex As Exception
' myMessageBox(ex.Message, "manipulateData - fillPropertyGrid",
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Public Overloads Overrides Function GetStandardValuesSupported(ByVal
context As ITypeDescriptorContext) As Boolean
Return True
End Function 'GetStandardValuesSupported
Public Overloads Overrides Function GetStandardValuesExclusive(ByVal
context As ITypeDescriptorContext) As Boolean
Return True
End Function 'GetStandardValuesExclusive
Public Overloads Overrides Function GetStandardValues(ByVal context As
ITypeDescriptorContext) As StandardValuesCollection
Return events
End Function
End Class 'EventConverter
================================================== ==
I am facing two problems
a. In the New Sub of the EventConverter class, instead of windows controls i
want to get the type of web controls. So the line : myTypeEvent =
GetType(System.Windows.Forms.Label)
should look something like : myTypeEvent =
GetType(System.Web.UI.WebControls.Label)
My problem is that System.Web.UI.WebControls.Label is not an option (perhaps
cos i am developing a vb.net project). How can i get the type of web controls
?
b. The New sub of the EventController class is run only once. So if i select
the in the "editorStyle" property the es_label and i open the "events"
collectionEditor, then the "event" property should be filled in with the
labels events. If i then change my selection and chooce textbox then the New
sub is not run again, and so the label's events are still shown in the
"event" property of the collectionEditor (instead of the button's events)
My apologies for the lengthy email
thx a lot
theodore