Saturday, March 31, 2012

Why is there no clear info on Dropdownlist in PropertyGrid so hard?

The simplicity of the example will explain itself. Code has been stripped down.

Private _itemID as string
Private _itemName as string
Private _itemType as string
Private _width as integer

Each private variable has its own simple property following standard same pattern:

<Category("Behavior"), Browsable(True)> _
Public Property ItemID() As Integer
Get
Return _item Set(ByVal Value As Integer)
_item = Value
End Set
End Property

The ItemID property will be bound to values from an XML file .When ItemID is changed, the other 3 properties will be automagically populated with the item's respective values from same XML file.

That's ALL I WANT!

Problems I've encountered:

1. Populating dropdownlist2. Firing event to trigger updating of the other properties.3. All the examples I find are in:-- VB.NET/ Windows forms which uses different objects in UITypeEditor-- Too complex to follow for ASP.NET webform-- Not In VB (not a biggie, but helpful if i can avoid symantical differences in a C# to VB conversion)

I am an ASP.NET/VB programmer just looking to have happy life.

Answers to some of you questions..

Regarding populating dropdownlist seehttp://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/standard/dropdownlist.aspx

Regarding Firing of events could you not set the values of the other properties in the set part of your property accessor just after _itemID = value set the other properties.

I am assuming here you have all the mechanism to read data from your XML file.


To answer your questions: yeah I know how to bind dropdownllist from XML. My question was more where does this happen in control or the TypeEditor? Those othe properties should be editalbe, not ReadOnly, and yes, firing event won't be necessary. This posted code below was left out for simplicity. I hope it helps better explain my problem:

<Category("Behavior"), _
Browsable(True), _
Editor(GetType(MyDropDownListEditor), GetType(UITypeEditor))> _
Public Property ItemID() As String
Get
Return _itemID
End Get
Set(ByVal value As String)
_itemID = value
End Set
End Property

The UTITypeEditor code is provided

Public Class MyDropDownListEditor
Inherits System.Drawing.Design.UITypeEdit

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

If context Is Nothing _
OrElse provider Is Nothing _
OrElse context.Instance Is Nothing Then
Return MyBase.EditValue(provider, value)
End If

Try
*** WHAT GOES HERE **
Where i.e. where do I fill the drop-down lslist

Catch ex As Exception
Throw New Exception("Error in EditValue Routine")
End Try
Return MyBase.EditValue(context, provider, value)
End Function EditValue

End Class

0 comments:

Post a Comment