473,546 Members | 2,243 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HELP: C# - ListBox.SetSele cted 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 2802
Maybe you should move your pre-selection code into Load event?

HTH
Alex

"Andrew" <tr******@hotma il.com> wrote in message
news:b7******** *************@n ews20.bellgloba l.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***********@ SPAMsympaticoPL EASE.ca> wrote in message
news:OV******** ******@tk2msftn gp13.phx.gbl...
Maybe you should move your pre-selection code into Load event?

HTH
Alex

"Andrew" <tr******@hotma il.com> wrote in message
news:b7******** *************@n ews20.bellgloba l.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******@hotma il.com> wrote in message
news:Ch******** *************@n ews20.bellgloba l.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***********@ SPAMsympaticoPL EASE.ca> wrote in message
news:OV******** ******@tk2msftn gp13.phx.gbl...
Maybe you should move your pre-selection code into Load event?

HTH
Alex

"Andrew" <tr******@hotma il.com> wrote in message
news:b7******** *************@n ews20.bellgloba l.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
1501
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 to initialize selection on the listbox! Anyone have any suggestions? TIA, John
5
5664
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 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...
3
2249
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 a mylistbox.SetSelected(0,true) so that the first item starts off selected. It is a MultiSimple listbox. What happens is nothing. The form draws...
9
45448
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 the listbox. Thanks, Alpha
3
3528
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 selects one item out of the 'all selected' listing then there is now only one item selected. How and where can I put in some code to change the...
5
7287
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 selected items is by: Dim item as String For Each item In lbItems.SelectedItems ' process the item Next
18
2001
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 unselected. when listbox2 is selected, 1 and 3 should have no items selected and the same with listbox 3. Sounds simple... should be simple! I have...
4
1474
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 programming thing and I'm having a little trouble with the syntax of my code. My code contains a bound listbox where the display member and value...
2
12712
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 sample like the following is working...but it is not working when the list contains an object. int cnt = listBox2.Items.Count; for (int i = cnt; i <...
0
7507
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7435
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7794
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6030
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5361
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5080
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3492
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3472
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1922
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.