Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6563145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:47:42+00:00 2026-05-25T13:47:42+00:00

Say I had a ComboBox with these values: Black Red Blue And I have

  • 0

Say I had a ComboBox with these values:

Black
Red
Blue

And I have Red currently selected. If the user then hits backspace and hits enter I am capturing the KeyDown event of the ComboBox.

In this event I want to delete Red from the list of items in the ComboBox.

However, because the text of the ComboBox is blank by the time KeyDown is called, the SelectedIndex is -1.

Currently I have a workaround that looks like this:

private void myComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
    currentMyComboBoxIndex = myComboBox.FindStringExact(myComboBox.Text);
}

Which works.. but I was just wondering if there is a better way. It seems like this way could break somehow and it seems a bit messy. Is there no way to get the current index of the ComboBox without having to keep track of it with a member variable and updating it when the index changes?

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T13:47:42+00:00Added an answer on May 25, 2026 at 1:47 pm

    The way you are doing is fine. You have to keep the selected index in memory because it returns -1 as the SelectedIndex when the text is deleted. You could take the index in this way too.

    private void myComboBox_SelectedIndexChanged(object sender, EventArgs e)
    {
        currentMyComboBoxIndex = myComboBox.SelectedIndex;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I had the following: <select disabled=disabled style=border: 1px red solid; color: black;> <option>ABC</option>
I have two combo boxes. Let's say the first one had values A, B,
Say you had a timestamp function and then wanted to create a new function
Say I had a String: Hello! I have to do all this: Convert string
Say I had a User class like this: public class User { public bool
Say I had the following values { Great, Good, Ok, Poor, Sucks } I
Say I had the Scanner method, and I want to print the user input
let say i had this two facts. animal(fifi,10). animal(fofo,20). If i call animal(X,Y). then
Lets say you had an entity called Bus. In that entity you have a
Say I had the two tables below, how do I find all questions with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.