Setting the selected value in a listbox
-
Hi, I am strugling with the propertygrid and a listbox. I am using the universaldropdowneditor from the codeproject (code below). However I am populating the listbox via a datasource. The problem I am having is that when I have a value in the propertygird and edit that, I want the listbox to have the selectvalue equal to the value that is being edited. Just to make it clearer: PropgridVal = Germany Datasource= Belgium France Italie Germany Currently when I edit a value it defaults directly to Belgium, instead of Germany I do not understand, when I use listbox.selectedvalue="Germany" the selectedvalue remains Nothing please help David J Thankks David J #Region " UniversalDropdownEditor class " Public Class UniversalDropdownEditor Inherits UITypeEditor Private edSvc As IWindowsFormsEditorService Private valMemb As ValueMemberAttribute Public Overloads Overrides Function GetEditStyle(ByVal context As _ ITypeDescriptorContext) As UITypeEditorEditStyle If Not context Is Nothing AndAlso Not context.Instance Is Nothing Then Return UITypeEditorEditStyle.DropDown End If Return UITypeEditorEditStyle.None End Function _ Public Overloads Overrides Function EditValue( _ ByVal context As ITypeDescriptorContext, _ ByVal provider As System.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 ' Dim att As SourceCollectionAttribute = _ ' context.PropertyDescriptor.Attributes( _ ' GetType(SourceCollectionAttribute)) 'If att Is Nothing Then ' nothing we can do here 'Return MyBase.EditValue(provider, value) 'End If Me.edSvc = provider.GetService(GetType(IWindowsFormsEditorService)) 'If Me.edSvc Is Nothing Then ' nothing we can do here either 'Return MyBase.EditValue(provider, value) 'End If 'prepare the listbox Dim lst As New ListBox() Me.PrepareListBox(lst, context) If Me.valMemb Is Nothing Then lst.SelectedItem = value Else Me.valMemb.SelectByValue(lst, value) End
-
Hi, I am strugling with the propertygrid and a listbox. I am using the universaldropdowneditor from the codeproject (code below). However I am populating the listbox via a datasource. The problem I am having is that when I have a value in the propertygird and edit that, I want the listbox to have the selectvalue equal to the value that is being edited. Just to make it clearer: PropgridVal = Germany Datasource= Belgium France Italie Germany Currently when I edit a value it defaults directly to Belgium, instead of Germany I do not understand, when I use listbox.selectedvalue="Germany" the selectedvalue remains Nothing please help David J Thankks David J #Region " UniversalDropdownEditor class " Public Class UniversalDropdownEditor Inherits UITypeEditor Private edSvc As IWindowsFormsEditorService Private valMemb As ValueMemberAttribute Public Overloads Overrides Function GetEditStyle(ByVal context As _ ITypeDescriptorContext) As UITypeEditorEditStyle If Not context Is Nothing AndAlso Not context.Instance Is Nothing Then Return UITypeEditorEditStyle.DropDown End If Return UITypeEditorEditStyle.None End Function _ Public Overloads Overrides Function EditValue( _ ByVal context As ITypeDescriptorContext, _ ByVal provider As System.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 ' Dim att As SourceCollectionAttribute = _ ' context.PropertyDescriptor.Attributes( _ ' GetType(SourceCollectionAttribute)) 'If att Is Nothing Then ' nothing we can do here 'Return MyBase.EditValue(provider, value) 'End If Me.edSvc = provider.GetService(GetType(IWindowsFormsEditorService)) 'If Me.edSvc Is Nothing Then ' nothing we can do here either 'Return MyBase.EditValue(provider, value) 'End If 'prepare the listbox Dim lst As New ListBox() Me.PrepareListBox(lst, context) If Me.valMemb Is Nothing Then lst.SelectedItem = value Else Me.valMemb.SelectByValue(lst, value) End