• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 212
  • Last Modified:

How to programatically select an item in a multi-exteded listbox

My listbox is fully populated, and based upon certain program conditions, I want to select certain (multiple) items programatically.

I would expect something like this to work:
     LB_Clients.Items(i).selected = True
but it simply gives me an error message


Thanks in advance for your help.

Extra points due to urgency
0
bobdowdy
Asked:
bobdowdy
  • 2
2 Solutions
 
AlexFMCommented:
Use ListBox.SetSelected Method to select/unselect items in multiple-selection ListBox.

http://msdn2.microsoft.com/en-us/library/system.windows.forms.listbox.setselected.aspx
0
 
pradeepsudharsanCommented:
ListBox1.SelectedIndex = 1
i.e

ListBox1.SelectedIndex = i
0
 
pradeepsudharsanCommented:
 'Syntax: ListBox1.SetSelected(index,boolean value)
       
        ListBox1.SetSelected(1, True) 'To select the item
        ListBox1.SetSelected(1, False) 'To unselect the item
0
 
bobdowdyAuthor Commented:
Thanks a million - I split points because while alex was first, pradeep provided answer instead of reference. Thanks again.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now