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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:29:53+00:00 2026-06-09T13:29:53+00:00

Disclaimer – I’ve only been using C# for about a week now, so hopefully

  • 0

Disclaimer – I’ve only been using C# for about a week now, so hopefully this isn’t a n00b question. I did look around, but was unable to find a solution that worked, including the results from this thread.

I have a combobox on a Windows form. The combobox’s data is populated from an Access database. The relevant properties that I have set are – AutoCompleteMode = Append; AutoCompleteSource = ListItems; DropDownStyle = DropDown. The users must be able to type in the combobox and it autocomplete, so the DropDownStyle of DropDownList will not work. Instead of using the default drop down arrows I have a dynamic PictureBox replacing it. Clicking on the PictureBox or triggering the Enter event will set the DropDowned property of the combobox to true.

As it currently is, users can select items just fine or type in items and press enter or type in items and leave the field, etc…. During all of those different types of interactions I am able to determine what the correct value in the combobox is. I have certain triggers to ensure that the SelectedValue and the displayed Text are always in sync.

I am able to get the correct value under every possible interaction, that I could think of, except for one. If the user starts to type a string (with the DropDowned property = true) and hits the right arrow key to have the string autocomplete, the string in the combobox is always a null string.

Visual:

Selected_Text

The bolded text in the above string is the highlighted text in the combobox. If the user then hits the right arrow key to make the text in the combobox look like

Selected_Text

(Note that DropDowned is still true at this point) the ComboBox.Text value is always “”.

Here is the code for one of the ComboBoxes’ DropDownClosed event, which is the first thing that is triggered once the user presses enter.

private void cmbxYear_DropDownClosed(object sender, EventArgs e)
    {
        try
        {
            if (!cmbxYear.Text.Equals(cmbxYear.SelectedValue.ToString()))
            {
                if (!bUpdated & !bErrorFound)
                {
                    validateData(cmbxYear, clrYear, false, imgFilter1, imgNoFilter1);
                    updateTable();
                }
            }
            imgFilter1.Visible = false;
            imgNoFilter1.Visible = true;
        }
        catch
        {
            imgNoFilter1.Visible = false;
            imgFilter1.Visible = true;
        }
    }

I also just discovered that the ComboBox.Text is always a null string when the DropDowned property = true and a user has typed something in and then presses “Enter”. This is not the case if the DropDowned property = false. When that occurs the correct string is returned.

I have even tried having the program select all of the text in the comobox; however, giving a value for the SelectionLength greater than the ComboBox.Text.Length does not appear to work. I have also tried referring to the SelectedValue; however, the SelectedValue is null.

For all intensive purposes the application is convinced that there is a null string in the combobox.

How can I retrieve the actual string?


In case this helps I have code for the following events: Click, DataSourceChanged, DropDown, DropDownClosed, Enter, KeyDown, Leave, and Validated.

  • 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-06-09T13:29:55+00:00Added an answer on June 9, 2026 at 1:29 pm

    I was able to create a successful workaround to this apparent bug. Below is my workaround; hopefully, this code will help others. Note: You may need to add other event handlers to fine tune all of your ComoBoxes’ user interactions, but this will work for the problem I described in my question.

    To use this code you will need a ComboBox on your form called cmbxTest. You will also need to add the appropriate event handlers. Assuming your form name is frmMain as used below, in the fmrMain.Designer.cs file, add this code (note you will want other items too, but these are the new items that will needed to be added to the ComboBox, cmbxTest, that should already be on your test form, frmMain):

    this.cmbxTest.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Append;
    this.cmbxTest.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
    this.cmbxTest.DropDownClosed += new System.EventHandler(this.cmbxTest_DropDownClosed);
    this.cmbxTest.KeyUp += new System.Windows.Forms.KeyEventHandler(this.ComboBoxKeyUp);
    this.cmbxTest.Text = "Test";  // Used in the below example - The default displayed text
    

    In the class file for the form (frmMain.cs in this example), make it look something like the following:

    public partial class frmMain : Form
    {
        // Intial Declerations and initializations
        Boolean bReady = false;       // Secondary trigger for DataGridView selection
        string clrTest = "Test";      // Default display text - Clear filter text; Used to ignore the setting if this text is visible
        string currentText;           // Comboboxes' currently displayed text
    
        // Form execution
        public frmMain()
        {
            InitializeComponent();
        }
    
        // Some code...
    
        //
        // ComboBoxes on KeyPress event
        //      - Used as a workaround for MS ComboBoxes not updating their text correctly
        //      - Shared across all ComboBoxes (as applied by the individual controls' event handlers)
        //
        private void ComboBoxKeyUp(object sender, KeyEventArgs e)
        {
            ComboBox cmb = (ComboBox)sender;
            currentText = cmb.Text;
        }
    
        // Any trigger you want that requires the ComboBoxes text
        private void cmbxTest_DropDownClosed(object sender, EventArgs e)
        {
            if (!cmbxTest.Text.Equals(clrTest))
            {
                cmbxTest.Text = currentText;
            }
            // Do any other code that requires the cmbxTest.Text
            Console.WriteLine(cmbxTest.Text);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Disclaimer: This question is not about fixing visual studio So, I've used VSS for
Disclaimer: I know this type of question has been asked here before, I just
( DISCLAIMER : This is NOT a question about understanding the difference between abstract
Disclaimer: this question is strictly about mysql and database abstraction layers that support it.
Disclaimer: this question is driven by my personal curiosity more than an actual need
Disclaimer, I'm not a PHP programmer, so you might find this question trivial. That's
Disclaimer : I already asked this question , but without the deployment requirement. I
Disclaimer : this is a strange issue that only happens in a Kindle Fire
Disclaimer: this question is purely informational and does not represent an actual problem I'm
Disclaimer: The author of this post has only theoretical and almost no practical knowledge

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.