HELP: C# - ListBox.SetSelected Not Working Properly!

  • Thread starter Thread starter Andrew
  • Start date Start date
A

Andrew

I'm having a major problem with a databound listbox in C#. In the
constructor for the form I am trying to pre-select some of the items based
in information in the database. When I step through the debugger it all
seems to be working properly until the Load function is called, and then all
my selections but 1 are unselected. Anybody had any experience with this
and know of a fix?

Listbox is databound
Listbox appears on a tabpage inside a tabcontrol, inside a form
SetSelected works in contructor
All but one item unselected at beginning of load

Thanks for any help,
Andrew
 
Tried that already, doesn't seem to work. Actually, I tried loading it upon
activation and that only worked once I changed the focus to the tabpage
where the listbox was. I thought that fixed it but it turns out as soon as
the listbox loses focus all but one of the selections gets unselected (I
have it on multi-simple).

Andrew
 
No clue really, Andrew

However, if you could really check if selection (check collection count and
items) is really lost when focus is moved.
It could be just redraw issue.

About activation - do you mean Activate event handler?

I use mostly ListView, which doesn't lose selection(s) when focus is lost.
Listbox should be also stable.
Maybe you can simplify sample and post code illustrating problem?

HTH
Alex
 
Have you set the ListBox.SelectionMode to either MultiSimple or MultiExtended? Default is always One and then no matter how many items you select only one is shown as selected

Hope this help
Marcello
 
Yes, I'm using multi-simple. The Listbox works fine if I populate it
manually, but if I use a DataTable I have all sorts of problems.

Andrew

Marcello said:
Have you set the ListBox.SelectionMode to either MultiSimple or
MultiExtended? Default is always One and then no matter how many items you
select only one is shown as selected.
 
Back
Top