adding listbox selected items

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lord.zoltar@gmail.com

    #1

    adding listbox selected items

    Hello
    I'm trying to programmaticall y set a listbox to have several items
    selected when it is loaded. Which items are selected is based on a
    saved user setting.
    Right now, I'm trying:
    Me.my_ListBox.S electedIndices. Add(item)
    This throws exceptions.
    What is a safe way to add indices to the SelectedIndices list?

  • Kerry Moorman

    #2
    RE: adding listbox selected items

    lord.zoltar,

    From your example, it looks like you have the items that should be selected.
    In that case:

    Me.my_ListBox.S electedItems.Ad d(item)

    Kerry Moorman


    "lord.zoltar@gm ail.com" wrote:
    Hello
    I'm trying to programmaticall y set a listbox to have several items
    selected when it is loaded. Which items are selected is based on a
    saved user setting.
    Right now, I'm trying:
    Me.my_ListBox.S electedIndices. Add(item)
    This throws exceptions.
    What is a safe way to add indices to the SelectedIndices list?
    >
    >

    Comment

    • Tim Patrick

      #3
      Re: adding listbox selected items

      You can use the ListBox control's SetSelected method. Pass it the position
      of the list item, and a boolean value, True in this case.

      ListBox1.SetSel ected(itemPosit ion, True)

      Make sure that you have also set the SelectionMode property for the control
      as needed.

      -----
      Tim Patrick - www.timaki.com
      Start-to-Finish Visual Basic 2005
      Hello
      I'm trying to programmaticall y set a listbox to have several items
      selected when it is loaded. Which items are selected is based on a
      saved user setting.
      Right now, I'm trying:
      Me.my_ListBox.S electedIndices. Add(item)
      This throws exceptions.
      What is a safe way to add indices to the SelectedIndices list?

      Comment

      Working...