Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / August 2005

Tip: Looking for answers? Try searching our database.

How to delselect items in databound ListBox or ComboBox

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
andersonwebdev@hotmail.com - 12 Aug 2005 04:48 GMT
When I use the DataSource property of a ListBox or ComboBox, there is
always a selected item.  When I bind the control, I don't want anything
selected.  I have tried using the .SetSelected() method, setting,
selectedIndex to -1 (twice in a row, blah blah), setting SelectedItem
to null, etc.

listBoxInventorParts.DataSource = _selectedInventorParts;
listBoxInventorParts.DisplayMember = "InventorPartNumber";
listBoxInventorParts.ValueMember = "pkInventorPartId";

// Doesn't work
listBoxInventorParts.SelectedIndex = -1;

// Doesn't work
listBoxInventorParts.SelectedItem = null;

// Doesn't work
listBoxInventorParts.SelectedValue = null;

// Doesn't work
listBoxInventorParts.ClearSelected();

// Doesn't work
for(int i = 0; i < listBoxInventorParts.Items.Count; i++)
{
   listBoxInventorParts.SetSelected(i, false);
}

Nice.
andersonwebdev@hotmail.com - 12 Aug 2005 15:11 GMT
Found the answer.  It's a bug in my view.  I was doing the databinding
in Form_Load, and attempting to deselect items in the Load event did
not work. I discovered that to deselect any items, I had to do it in
the Form_Paint event:

private void InventorAssemblyTreeStep3_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{
    listBoxInventorParts.SelectedItem = null;
}

- Matt

> When I use the DataSource property of a ListBox or ComboBox, there is
> always a selected item.  When I bind the control, I don't want anything
[quoted text clipped - 25 lines]
>
> Nice.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.