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 7071067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:38:33+00:00 2026-05-28T05:38:33+00:00

I want to make a ComboBox where the user can type an integer value

  • 0

I want to make a ComboBox where the user can type an integer value into the text area, but the drop-down list contains several “defaults” values. For instance, the items in the drop-down list would be formatted like this:

  • Default – 0
  • Value 1 – 1
  • Value 2 – 2

What I want is that when the user selects an item (e.g. “Default – 0”), the ComboBox text will display only the number “0” rather than “Default – 0”. The word “Default” is just informational text.

I have played with the following events: SelectedIndexChanged, SelectedValueChanged, and SelectionChangeCommitted, but I was not able to change the text of the ComboBox.

private void ModificationCombobox_SelectionChangeCommitted(object sender, EventArgs e)
{
     ComboBox comboBox = (ComboBox)sender; // That cast must not fail.
     if (comboBox.SelectedIndex != -1)
     {
        comboBox.Text = this.values[comboBox.SelectedItem.ToString()].ToString(); // Text is not updated after...
     }
 }
  • 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-28T05:38:34+00:00Added an answer on May 28, 2026 at 5:38 am

    You can define a class for your ComboBox item, then create a List<ComboBoxItem> and use it as your Combobox.DataSource. With this you can set ComboBox.DisplayMember to a property you want displaying and still get reference to your object from ComboBox_SelectedIndexChanged():

    class ComboboxItem
    {
      public int Value { get; set; }
      public string Description { get; set; }
    }
    
    public partial class Form1 : Form
    {
      List<ComboboxItem> ComboBoxItems = new List<ComboboxItem>();
      public Form1()
      {
        InitializeComponent();
        ComboBoxItems.Add(new ComboboxItem() { Description = "Default = 0", Value = 0 });
        ComboBoxItems.Add(new ComboboxItem() { Description = "Value 1 = 1", Value = 1 });
        ComboBoxItems.Add(new ComboboxItem() { Description = "Value 2 = 2", Value = 2 });
        comboBox1.DataSource = ComboBoxItems;
        comboBox1.DisplayMember = "Value";
    
      }
    
      private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
      {
        var item = (ComboboxItem)((ComboBox)sender).SelectedItem;
        var test = string.Format("Description is \'{0}\', Value is  \'{1}\'", item.Description, item.Value.ToString());
        MessageBox.Show(test);
      }
    }
    

    [edit]
    If you want to change displayed text when box toogles between DropDown states try this: (this is a concept, not sure how that would behave)

        private void comboBox1_DropDown(object sender, EventArgs e)
        {
            comboBox1.DisplayMember = "Description";
        }
    
        private void comboBox1_DropDownClosed(object sender, EventArgs e)
        {
            comboBox1.DisplayMember = "Value";
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make sure people can't type the name of a PHP script
Goal: The user should not make any changes in the text field in Combobox.
I am traversing a HTML document using javascript DOM. I want make a list
I want to make an entity that has an autogenerated primary key, but also
Here's the situation: i have a SearchPage where an user can make a complex
I want to make window with few panels. I can append one to MainFrame's
I have a Nationality ComboBox like the one below and want to make it
I have a ComboBox with a remote json store. It lets the user type
I have an editable ComboBox with a validation on the Text property to make
I've been trying to make a ComboBox which would suggest options as you type,

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.