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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:15:46+00:00 2026-05-13T07:15:46+00:00

Ok, firstly I have the following code working.. although my question is this; should

  • 0

Ok, firstly I have the following code working.. although my question is this; should I code the combobox databinding like the following example, or is there an easier/more efficient way?

Firstly, I needed to manipulate the results back from the database to show a more descriptive meaning:

(I am using a basic class for the key/value pair)

class WashBayDesc
    {
        public string Key { get; set; }
        public string Text { get; set; }
    }

Now I retrieve the data from a datareader and do the manipulation I need which then adds the results to a list item:

    var washbaydata = new List<WashBayDesc>();

    //  Read through the available cashboxes and populate a list/combobox
    while (rdr.Read())
    {
        string sWashBayDesc = null;
        string sWB = rdr["washbay"].ToString();
        if (sWB.StartsWith("3"))
        {
            sWashBayDesc = "Bay " + sWB.Substring(1);
        }
        else
        {
            sWashBayDesc = "Auto " + sWB.Substring(1);
        }

        washbaydata.Add(new WashBayDesc { Key = sWB, Text = sWashBayDesc });
    }

        //  Now bind the hashtable (with our bay selectors) to the dropdown
        cmbCashBoxes.DataSource = washbaydata;
        cmbCashBoxes.ValueMember = "Key";
        cmbCashBoxes.DisplayMember = "Text";

So.. the idea is I can simply bind the ComboBox datasource to the washbaydata list object.. this works fine.

The next part is to retrieve the selected item value (i.e. not the textual description, but the value or key itself). This is the bit I think maybe doesn’t quite look right, although again it works…

    WashBayDesc myRes = new WashBayDesc();
    myRes = (WashBayDesc)cmbCashBoxes.SelectedItem;
    string sWashBayCashBox = myRes.Key;

So the result is my string sWashBayCashBox has the selected key…

I guess it works, and that is fine, but is there an easier/more cleaner way?

  • 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-13T07:15:46+00:00Added an answer on May 13, 2026 at 7:15 am
    string sWashBayCashBox = (string)cmbCashBoxes.SelectedValue;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 270k
  • Answers 270k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer CREATE ASSEMBLY [RegularExpression] AUTHORIZATION [dbo] FROM < DLL Path >… May 13, 2026 at 1:27 pm
  • Editorial Team
    Editorial Team added an answer You can just take the EXE as long as it… May 13, 2026 at 1:27 pm
  • Editorial Team
    Editorial Team added an answer I'd be interested in the reasons for your requirements. Why… May 13, 2026 at 1:27 pm

Related Questions

Ok, firstly I've seen this thread . But none of the solutions are very
I'm trying to writing a generic method that will load a record of a
Ok, I asked this question before, but deleted it as the way I went
In a MVC view, I have a form as below. when user click on
Firstly, I know I should be using proper Threading techniques (Threadpool, BeginInvoke, etc.) to

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.