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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:57:15+00:00 2026-05-27T13:57:15+00:00

I am using Windows Forms , and I have a combo box with the

  • 0

I am using Windows Forms, and I have a combo box with the values:

Apple
Oranges
Pairs

My text box contains values 1, 2 and 3,

apple = 1 and oranges = 2 and pairs = 3.

This relation is in my table on SQL, fields Account and Name. How do I change the value of the textbox to = 2 if the combo box is selected as oranges?

Basically this is reference to a program I’m working on that has an account combo box that displays the accounts names (user friendly). I need the names ID account number to then be displayed in the text box. From this text box I can then pass the value into my stored procedure that will get all the information on that account.

Update

The above text is out of date. See below!

A note to add is that my code gets the account details and populates my combo box.

Is there an easy way to do this? Or does this require joining in C# similar to SQL joins on tables?

Or without using a text box at all, basically my combo would have 2 fields orange, 2 but only display oranges to the user, but my other method uses the second field 2.

OK, so this part adds the acc field to the combo box.

{
    SqlCommand accountFill = new SqlCommand("SELECT name, acc FROM dbo.Customer", conn1);
    SqlDataReader readacc = accountFill.ExecuteReader();

    while (readacc.Read())
    {
        AddItem(readacc.GetString(0).ToString(), readacc, "name", "acc");
    }
    conn1.Close();
}

Add item is an invoke method used by my task.

private void AddItem(string value, Object dataSource, string name, string acc)
{
    if (accCollection.InvokeRequired)
    {
        accCollection.Invoke(new Action<string,Object,string,string>(AddItem), new Object[] { value });
    }
    else
    {
        //accCollection.Items.Add(value);
        accCollection.DataSource = dataSource;
        accCollection.DisplayMember = name;
        accCollection.ValueMember = acc;
    }
}

ERROR complex databinding accepts as a datasource iether an i.list or an i.list source at datasource.

  • 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-27T13:57:16+00:00Added an answer on May 27, 2026 at 1:57 pm

    The ComboBox class has two properties ValueMember and DisplayMember. You need to set the DisplayMember property to the Names of your table or data, i. e. orange, apple, etc… ,and set the ValueMember property to the Id’s of them:

    combobox1.Datasource = readacc;
    combobox.DisplayMember = 'name';
    combobox.ValueMember = 'acc';
    

    All you need then is just use the two properties SelectedValue to get the Id or SelectedText to get the value. For example, you could get the id of the selected item by using ComboBox.SelectedIndexChanged Event like this:

    private void ComboBox1_SelectedIndexChanged(object sender, 
        System.EventArgs e)
    {
        textbox2.text = int.parse(combobox1.SelectedValue.ToString());
    }
    

    or you can get the select text like:

    textbox2.text = combobox1.SelectedText;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using windows forms application using C#. I have created a dialog box
I am using windows application and I have four combo boxes(comboeventname,combosendtype,comboType,comboschedule) in that form....
Could someone provide an example for drawing graphics without using Windows Forms? I have
I am using standard windows forms controls under C#. I have two controls which
How do I enable double-buffering of a control using C# (Windows forms)? I have
I have a little demonstration below of a peculiar problem. using System; using System.Windows.Forms;
I am using C# and Windows Forms. I have a normal progress bar working
We have a fairly complicated GUI in windows forms using C# and .Net 2.0.
I have previously written user interfaces using .NET and Windows Forms. I'm about to
I have created a Windows Forms application in .NET 2 using C# that runs

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.