ListBox SelectionMode

L

lgbjr

Hi All,

I've got a listbox on a VB.NET form. when the form opens, the ListBox
SelectionMode is set to Single. while running various routines on the form,
items get added to the list box (results of computations, etc).

when all of the calculations are complete, I'm trying to change the listbox
selection mode from single to MultiExtended, using:

myListBox.SelectionMode=SelectionMode.MultiExtended

However, it's not working. I can still only select one item.

By the way, the reason I start with the listbox selection mode set to single
is that as items are added to the listbox, I always have the last item
selected:

myListBox.SelectedIndex=myListbox.Items.Count-1

this way, as items are added, the list automatically scrolls, so the latest
information is always visible.

But, when the calcs are finished, I want the user to be able to select
whatever they want and copy/paste elsewhere, which is why I'm trying to
switch to MultiExtended

Also, by the way, if I start with the SelectionMode set to MultiExtended, I
can select multiple items, so it's only switching from one to the other that
isn't working.

Any Ideas?

tia
Lee
 
C

CT

I have no problems doing that here, in a Windows Form. Are you talking about
a Web page?
 
L

lgbjr

No, it's a windows form (specifically, it's an MDI Child form). Setting the
SelectionMode at design time works fine, but trying to change it at runtime
is just being ignored (no exception, nothing)

On another list, someone said they thought the SelectionMode was a
designtime only property (which is the way it's acting), but I'd expect a
build error or an exception if that were the case.

Lee
 
C

CT

Hi Lee,

Not at all sure why you're experincing this, as the SelectionMode property
is not a design-time only property, i.e. read-only at run-time. After you
set the property, what is it set to, if you read it? You're not by any
chance trying to update the property from a background thread?
 
L

lgbjr

LOL! Well, I'm not sure why I was having problems either. I was checking
that the SelectionMode was actually being set to MultiExtended, yet the
control was still acting like it was set to one.

However, and I sware it was really happening, it's not happening now. Not
because of this issue, but I have rebooted the machine, but I don't know if
that's what fixed the problem (not likely). I just tried switching from one
to Multi and from multi to one and it works.

I switched the SelectionMode at designtime to MultiExtended, then just put a
listbox.clearselected after each item I added, then I select the last item.

I don't have time right now, but later today, I'm going to comment out
everything I added and set the designtime selectionmode back to one, then
try to reproduce the problem (just for my own sanity).

cheers,
Lee
 

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