How to select multiple items in ListBox control

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
 
V

Vitaly Zayko

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
 
I

Ignacio Machin \( .NET/ C# MVP \)

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,
 
T

ted

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top