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

  • Home
  • SEARCH
  • 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 6931139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:32:18+00:00 2026-05-27T11:32:18+00:00

I’ve made a previous post that tried to use a textbox. From this I

  • 0

I’ve made a previous post that tried to use a textbox. From this I found out you can simply add an sql query results (the excute reader) to the ComboBox and then display and use the other column value.

Problem I have is I’m using a task for my form that runs a different HUGE sql query so it does not lock up my controls in my form. The problem, in detail, is that I’m using an invoke method wrapped around that control that only gets the 1st column.

public void fillmycombo()
{
    SqlConnection conn1 = new SqlConnection(myConn1);
            conn1.Open();
            if (string.Compare(_userName, admin) == 0)
            {
                SqlCommand accountFill = new SqlCommand("SELECT name, FROM dbo.Customer", conn1);
                SqlDataReader readacc = accountFill.ExecuteReader();

                while (readacc.Read())
                {
                    AddItem(readacc.GetString(0).ToString());
                    //accCollection.DataSource = readacc;
                    //accCollection.DisplayMember = "name";
                    //accCollection.ValueMember = "keycode";

                }
                conn1.Close();
            }
}

this method as you can see gets the name.

    private void AddItem(string value)
    {
        if (accCollection.InvokeRequired)
        {
            accCollection.Invoke(new Action<string>(AddItem), new Object[] { value });
        }
        else
        {

            accCollection.Items.Add(value);
        }
    }

as you can see im using the invoke method to wrap the control for use in my method that is on the task.

private void button1_Click_1(object sender, EventArgs e)
{
    checkBox1.Checked = true;
    string acct = accCollection.Text;
    Task t = new Task(() => GetsalesFigures(acct));
    t.Start();
}

this runs the task that calls my giant query method.

private void getsalesfigures(string acct)
{
    string acct;// test using 1560
            SqlConnection conn = new SqlConnection(myConn);
            SqlCommand Pareto = new SqlCommand();
            BindingSource bindme = new BindingSource();
            SqlDataAdapter adapt1 = new SqlDataAdapter(Pareto);
            DataSet dataSet1 = new DataSet();
            DataTable table1 = new DataTable();

            acct = Acct;

            string fromDate = this.dateTimePicker1.Value.ToString("MM/dd/yyyy");
            string tooDate = this.dateTimePicker2.Value.ToString("MM/dd/yyyy");

            Pareto.Connection = conn;
            Pareto.CommandType = CommandType.StoredProcedure;
            Pareto.CommandText = "dbo.GetSalesParetotemp";
            Pareto.CommandTimeout = 120;

            Pareto.Parameters.AddWithValue("@acct", acct);
            Pareto.Parameters.AddWithValue("@from", fromDate);
            Pareto.Parameters.AddWithValue("@too", tooDate);

            SetCheckBoxValue(true);
            SetPictureBoxVisibility(true);

            adapt1.Fill(dataSet1, "Pareto");

            SetCheckBoxValue(false);
            SetPictureBoxVisibility(false);

            SetDataGrid(true, dataSet1, "Pareto", DataGridViewAutoSizeColumnsMode.AllCells);

            dataGridView1.AutoResizeColumns(
                DataGridViewAutoSizeColumnsMode.AllCells);
        }
        catch (Exception execc)
        {
            MessageBox.Show("Whoops! Seems we couldnt connect to the server!"
                            + " information:\n\n" + execc.Message + execc.StackTrace,
                            "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
        }
}

What I want to do is add another field to my query called “keycode”, store this in a 2nd column in my ComboBox and then display the name field for the user, but use the keycode field as the value to be used in my giant task query.

I’m having trouble figuring out how I to do this.

  • 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-27T11:32:19+00:00Added an answer on May 27, 2026 at 11:32 am

    In the past, I’ve used an object that contains an override of ToString() and instead of adding plain strings to my combo boxes (or other lists), I add these objects. Then, when you need to get the value of a selected item, you can cast it and do GetValue(). Here’s a sample.

    class LookupTableItem {
        private string Text;
        private object Value;
    
        public LookupTableItem(string Text, object Value) {
            this.Text = Text;
            this.Value = Value;
        }
    
        public override string ToString() {
            return Text;
        }
    
        public object GetValue() {
            return Value;
        }
    }
    

    Then, change your AddItem to add items this way:

    accCollection.Items.Add(new LookupTableItem(text, value));
    

    And to retrieve the value:

    ((LookupTableItem)accCollection.Items[0]).GetValue();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't

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.