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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:14:37+00:00 2026-05-26T22:14:37+00:00

We have a project that sets the DataSource of a combobox, but allows users

  • 0

We have a project that sets the DataSource of a combobox, but allows users to either select something from this list OR type in an item not contained in the list. Basically, there is a Geobase that contains streets, but the users are not required to choose a street from the list. The ComboBox.DropDownStyle is set to DropDown.

If a user edits a record that contains a street NOT in the geobase (and therefore not in the ComboBox.DataSource) we are having issues populating the form correctly.

Here is a greatly simplified form of our problem:

    private void button1_Click(object sender, EventArgs e)
    {
        // Create a new form.  In the constructor the DataSource of the ComboBox is set with three items:
        //      Main St., First St., and Second St.
        ComboBoxTrialForm frm = new ComboBoxTrialForm();

        // Set comboBox1.Text equal to an item NOT in the datasource
        frm.SetComboTextValue("Michigan Ave.");

        // Show the form, and the comboBox has the first item in its datasource selected
        frm.Show();
    }

The ComboBoxTrial Class goes something like this:

public partial class ComboBoxTrialForm : Form
{
    public ComboBoxTrialForm()
    {
        InitializeComponent();
        List<string> streets = new List<string>() { "Main St.", "First St.", "Second St." };
        comboBox1.DataSource = streets;
    }

    public void SetComboTextValue(string text)
    {
        comboBox1.Text = text;
    }
}

I set break points and found that comboBox1.Text does indeed get set correctly. Interestingly I found that the BindingContextChanged event actually gets fired twice in this simplified example. Once in the constructor when comboBox1.DataSource = streets is called, and a second time when frm.Show() is called.

Why is this event firing when the form is shown, and is this why my manually set selection is getting removed? How should I go about correcting this behavior?

Also, am I incorrect in thinking that I should be able to use the combobox in this way?

Thanks in advance.

  • 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-26T22:14:37+00:00Added an answer on May 26, 2026 at 10:14 pm

    You should be able to set the SelectedIndex to -1 so that no item is selected in the list. I didn’t have any problem getting “Michigan Ave.” to display in the combo box with this method.

    public Form1()
    {
        InitializeComponent();
        comboBox1.DataSource = new List<string>() { "Main St.", "First St.", "Second St." };
        comboBox1.SelectedIndex = -1;
    }
    

    Also, you could show the form, and then set the text. Unless that’s a problem, the user probably won’t notice.

        frm.Show();
        frm.SetComboTextValue("Michigan Ave.");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a project that I'm currently working on but it currently only supports
I have a project that I thought was going to be relatively easy, but
I have a project that builds fine If I build it manually but it
I have CSLA (1.x framework) objects from an existing project that I'm trying to
I have a project that sets up several pages with articles. Each page has,
I have an unusual project that I need to display large sets of questions
We have a system that allows users interfacing data into the database to set
I have project that I'm working on that is going to require a webserver.
I have a project that I would like to start beta testing soon, it
I have a project that I'm working on and I need to be able

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.