Groups | Blog | Home
all groups > dotnet general > may 2004 >

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


Andrew
5/7/2004 6:25:06 PM
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

AlexS
5/7/2004 7:27:43 PM
Maybe you should move your pre-selection code into Load event?

HTH
Alex

[quoted text, click to view]

Andrew
5/7/2004 8:52:38 PM
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

[quoted text, click to view]

AlexS
5/7/2004 9:03:08 PM
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

[quoted text, click to view]

AddThis Social Bookmark Button