473,387 Members | 3,787 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,387 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 2777
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.