Results 1 to 3 of 3

Thread: How to unselect selected item of a combo box?

  1. #1
    .NET Framework
    .NET 4.5
    Join Date
    Jun 2018
    Posts
    21
    Rep Power
    6

    How to unselect selected item of a combo box?

    I have grappled with WPF-applications, and there is one thing that I could not glean from the documentation:

    If I have a WPF-Window with a Combo Box „comboBoxCars“ where the user can select, say some cars. I thereafter added a button „clearAll“, and as soon as that button is clicked, the following method is called:

    Code:
             private void OnButtonClick(object sender, RoutedEventArgs e)
            {
     
                //comboBoxCars how to unselect all previously selected items?
                     . . .          
                 
            }
    I would like to unselect any item in the comboBoxCars. How can I achieve this? If I simply write comboBoxCars.Items.Clear(); then there will be nothing left to select. Is there something like „unselect all“ or something similar?
    Last edited by aindrea; 06-21-2018 at 9:46 AM.

  2. #2
    .NET Framework
    .NET 4.5
    Join Date
    Jun 2018
    Location
    Texas
    Posts
    2
    Rep Power
    0
    Set the SelectedIndex to -1

  3. #3
    .NET Framework
    .NET 4.5
    Join Date
    Jun 2018
    Posts
    21
    Rep Power
    6
    Thanks! After all, I did it as follows. I added an empty element by dint of whose index I set it again as soon as the "clear" button is clicked.

Similar Threads

  1. Replies: 0
    Last Post: 02-22-2017, 11:26 PM
  2. Calling a method from a combo box selection?
    By DoJa in forum Windows Presentation Foundation (WPF)
    Replies: 1
    Last Post: 02-14-2017, 9:18 AM
  3. Question Filtering my DataGridView with Combo Boxes
    By Danielsm97 in forum Windows Forms
    Replies: 1
    Last Post: 02-23-2015, 5:00 PM
  4. Replies: 2
    Last Post: 02-23-2014, 10:08 PM
  5. Question Need logic for dropdown selected item while getting data to the page
    By mcfarland in forum C# General Discussion
    Replies: 0
    Last Post: 02-23-2014, 7:48 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •