473,480 Members | 2,014 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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
Nov 16 '05 #1
5 5661
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

Nov 16 '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


Nov 16 '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



Nov 16 '05 #4
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
Nov 16 '05 #5
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" <an*******@discussions.microsoft.com> wrote in message
news:90**********************************@microsof t.com...
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 helps
Marcello

Nov 16 '05 #6

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

Similar topics

3
2789
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...
0
1496
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...
3
2242
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
45430
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
3525
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...
6
1517
by: jez123456 | last post by:
Hi I have a windows form with 3 ListBoxes. m_listBoxUsers – this displays all users from a database. m_listBoxRoles – this displays available roles that can be assigned to users....
5
7277
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
1995
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
1462
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
12700
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
6920
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7060
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7022
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4799
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4501
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3013
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3004
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
572
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
206
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.