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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:04:42+00:00 2026-06-08T03:04:42+00:00

I am working on creating a form which pulls data from a database, and

  • 0

I am working on creating a form which pulls data from a database, and supplies two combo boxes. ComboBox1 shows Employee name in a “First name Last Name” format. ComboBox2 shows the Employee names in “Last, First” format. The names are pulling into the combo boxes without any difficulty.

What I am attempting to figure out how to do is once a user selects a name from either of the drop down boxes that it will populate certain text boxes such as, textBox1, textBox2 based on other information from the Query.

I have attempted to use

textBox1.Text = comboBox1.SelectedItem;

however, I get an error stating: Cannot implicitly convert type ‘object’ to ‘string’. An explicit conversion exists (are you missing a cast?)

Here is my current code. I have left out the connection queries to databases and such intentionally.

public partial class Employees : Form
{
    public Employees()
    {
        InitializeComponent();

        //Connect to database for Employees Table Headers
        SqlConnection myConnection = new SqlConnection(@"Server=Server...");

        try {
            myConnection.Open();
            string SqlDataPull = String.Format("SELECT * FROM Employees WHERE Lname IS NOT NULL {0} ORDER By Lname", (checkBox1.Checked ? "AND Active='Y'" : ""));
            SqlCommand cmd = new SqlCommand(SqlDataPull, myConnection);
            cmd.CommandType = CommandType.Text;
            SqlDataReader dr = cmd.ExecuteReader();

            while (dr.Read()) {
                string strEmployee = String.Format("{0}  {1}", dr["Fname"], dr["Lname"]);
                comboBox1.Items.Add(strEmployee);
                textBox1.Text = comboBox1.SelectedItem;
                string strEmployee2 = String.Format("{0}, {1}", dr["Lname"], dr["Fname"]);
                comboBox2.Items.Add(strEmployee2);
            }
        } catch (Exception e) {
            MessageBox.Show(e.ToString());
        } finally {
            if (myConnection != null) {
                myConnection.Dispose();
            }
        }
    }

    private void button1_Click(object sender, EventArgs e)
    {
        Main myNewForm = new Main();
        myNewForm.Show();
        this.Close();
    }

    private void button2_Click(object sender, EventArgs e)
    {
        Reports myNewForm = new Reports();
        myNewForm.Show();
        this.Close();
    }
}
  • 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-08T03:04:42+00:00Added an answer on June 8, 2026 at 3:04 am

    In your SelectedIndexChanged event, add the code:

    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
      if (comboBox1.SelectedIndex == -1) {
        textBox1.Text = string.Empty;
      } else {
        textBox1.Text = comboBox1.SelectedItem.ToString();
      }
    }  
    

    You should probably remove this statement from your while loop:

    // textBox1.Text = comboBox1.SelectedItem;
    

    because you just added the item to the ComboBox items collection, but you don’t actually know it’s been selected.

    Also, make sure you wire the event up:

    public Employees()
    {
      InitializeComponent();
    
      // yada-yada-yada
    
      comboBox1.SelectedIndexChanged += comboBox1_SelectedIndexChanged;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a form which updates two related models, for this example a
I'm creating an online poll from scratch which will be held in a database.
I'm working on the app which should download some data form server (done) and
I am dynamically creating forms based on values in a database. Each form element
I've been working on a small program which gets a list of url's from
I am working on creating an iphone application which logins to we website and
I am working on creating a progress bar for ffmpeg in java. So for
I'm working on creating a windows service that will send emails to a customer
I am working on creating a blog with ASP.Net 4, MVC 3, Razor and
I'm working on creating a map of Day Z (the game) with leaflet JS

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.