?
Solved

ListBox.ClearSelected() doesn't work

Posted on 2003-02-28
7
Medium Priority
?
444 Views
Last Modified: 2012-08-13
Whether my .SelectionMode is "One" or "MultiSimple", ClearSelected() selects the first item in the listbox.  Setting .SelectedIndex=-1 has the same effect.  

Any ideas how I can make no items selected without reinstantiating the whole damn control?

Here's my code (not that it really matters):

private System.Windows.Forms.ListBox lstExisting;
lstExisting.ClearSelected();          //doesn't work!!!
0
Comment
Question by:HarmnKardn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 2

Expert Comment

by:wiseguy_2112
ID: 8042386
are you sure you don't have any code else where that is changing the listbox?  Do you have any events on the list box?  I've tested this, and it does not behave the way you're saying.  
0
 
LVL 1

Author Comment

by:HarmnKardn
ID: 8042824
Yes, I have a _SelectedIndexChanged event on the listbox, but all that's done in the event is enable/disable some command buttons.  So, I commented out the code in the event handler just to be safe, and the problem still remains.
0
 
LVL 10

Expert Comment

by:smegghead
ID: 8043708
best thing to try, is start with a fresh project and just do it with the minimal bare bones.

If it still doesn't work, then there is a problem with your .net installation.

Otherwise, you've got to determine the differene between your current project and the cut-down dummy version you've just written.

Smg.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:HarmnKardn
ID: 8060400
It works if I use listbox.Items.Add(...) and add simple stuff like strings.  But if I add objects to the listbox and bind it to the datasource, it most assuredly doesn't work, it always changes the selection to the first item.

I'm convinced it's a bug with the control.   I haven't found any documentation about the problem.
0
 
LVL 1

Author Comment

by:HarmnKardn
ID: 8064684
Setting the ListBox.SelectedItem property to null accomplishes the intended goal of deselecting all items in a list bound to a DataSource.
0
 
LVL 1

Author Comment

by:HarmnKardn
ID: 8064785
I should note this workaround only seems to work if the .SelectionMode property is "MultiSimple".
0
 

Accepted Solution

by:
SpideyMod earned 0 total points
ID: 8064996
PAQ'd and points refunded.

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question