Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Setting the selected value in a listbox

Setting the selected value in a listbox

Scheduled Pinned Locked Moved Visual Basic
help
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    David M J
    wrote on last edited by
    #1

    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

    H 1 Reply Last reply
    0
    • D David M J

      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

      H Offline
      H Offline
      HarryBo
      wrote on last edited by
      #2

      Dim lIndex As Long lIndex = ListBox1.Items.IndexOf("Germany") ListBox1.SelectedIndex = lIndex Many Thanks Harry

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups