How to select multiple items in ListBox control

  • Thread starter Thread starter ted
  • Start date Start date
T

ted

Hi,

I can't figure out how to set multiple items in a ListBox to selected when
the listbox is in a User Control.

When the ListBox is set in directly into a form I can use the following:
listbox.SelectionMode = SelectionMode.MultiExtended;
listbox.SelectedIndex = 1;
listbox.SelectedIndex = 2;

But when I set the ListBox into a User Control, this doesn't work. I can
only set one item to selected.

Any help appreciated. TIA.

-Ted
 
Try this:
listBox.SetSelected(0, true);

Hi,

I can't figure out how to set multiple items in a ListBox to selected when
the listbox is in a User Control.

When the ListBox is set in directly into a form I can use the following:
listbox.SelectionMode = SelectionMode.MultiExtended;
listbox.SelectedIndex = 1;
listbox.SelectedIndex = 2;

But when I set the ListBox into a User Control, this doesn't work. I can
only set one item to selected.

Any help appreciated. TIA.

-Ted
 
Hi,

The weird thing is that it does work at all. I was under the impression
that the only way to select more than one item was using SetSelected method.


cheers,
 
This doesn't work for me when I have the ListBox in a UserControl.

It works when I have it in a panel or directly on a form. I can select
multiple items in those cases. It's just when the ListBox is on a
UserControl that I can't set it to more than one item.
 
Back
Top