473,322 Members | 1,405 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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

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
Jul 21 '05 #1
3 2773
Maybe you should move your pre-selection code into Load event?

HTH
Alex

"Andrew" <tr******@hotmail.com> wrote in message
news:b7*********************@news20.bellglobal.com ...
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

Jul 21 '05 #2
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

"AlexS" <sa***********@SPAMsympaticoPLEASE.ca> wrote in message
news:OV**************@tk2msftngp13.phx.gbl...
Maybe you should move your pre-selection code into Load event?

HTH
Alex

"Andrew" <tr******@hotmail.com> wrote in message
news:b7*********************@news20.bellglobal.com ...
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


Jul 21 '05 #3
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

"Andrew" <tr******@hotmail.com> wrote in message
news:Ch*********************@news20.bellglobal.com ...
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

"AlexS" <sa***********@SPAMsympaticoPLEASE.ca> wrote in message
news:OV**************@tk2msftngp13.phx.gbl...
Maybe you should move your pre-selection code into Load event?

HTH
Alex

"Andrew" <tr******@hotmail.com> wrote in message
news:b7*********************@news20.bellglobal.com ...
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



Jul 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: John Wood | last post by:
If you run SetSelected on an invisible ListBox it seems to ignore the call. This is especially annoying when the ListBox is on a tab control and the tab isn't selected at startup... it's impossible...
5
by: Andrew | last post by:
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...
3
by: Peter Mancini | last post by:
I have a simple winform with a listbox on it. I dynamically load the box with integers (the years 1975 to present.) This works fine and I can see the box has all of the items present. I then do...
9
by: Alpha | last post by:
Hi, How can I set all the items in a listbox to be selected? I can't find a property or mehtod to do it so I thought I'll try using setselected method but I need to find out how many items are in...
3
by: Alpha | last post by:
I have 3 radio buttons for include, exclued or 'select all' from the listbox items. If a user selects the 'Select All' button' then all items in listbox is hi-lited as selected. Now, when user...
5
by: Zack Sessions | last post by:
Using VB.NET. I have a ListBox control that I have populated with a list of items. The user selects one or more items from the list to process. The best way I have found to loop through the...
18
by: Dave Sauny | last post by:
Ok, its a friday, I'm at work and I cant get this to work: I have 3 listboxes on one tab control page. when i select an item in listbox1 i want whatever is selected on the other 2 listboxes...
4
by: SenileOwl | last post by:
I posted this in the Visual Basic Forum, but I've been wondering if .NET might be a better place for it. I'm working in Visual Basic Microsoft Visual Studio .NET 2005. I'm very new to the whole...
2
by: Ramk | last post by:
I have a listbox on my form which is bounded to a bindingsource. The collection is of type List<T>. If I add new elements to the bindingsource, I would like to select them in the listbox. A...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.