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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:04:02+00:00 2026-06-07T00:04:02+00:00

I have this form, in which i need to populate a combo box with

  • 0

I have this form, in which i need to populate a combo box with a text-value pair from the database, so that i can use the value in an update query to the database

i found some method that uses a class to make objects which have both text and a value as:

class RequestType
    {
        public string Text { get; set; }
        public string Value { get; set; }

        public RequestType(string text, string val)
        {
            Text = text;
            Value = val;
        }

        public override string ToString()
        {
            return Text;
        }

and i added them to the combo box like this

RequestType type1 = new RequestType("Label 1", "Value 1");
            RequestType type2 = new RequestType("Label 2", "Value 2");

            comboBox1.Items.Add(type1);
            comboBox1.Items.Add(type2);

            comboBox1.SelectedItem = type2;

now i don’t know how to retrieve the value of the selected item, i.e. id label 1 is selected, it must return value1 and if label 2 is selected, it returns value2,

any help please??? thanxx 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-06-07T00:04:03+00:00Added an answer on June 7, 2026 at 12:04 am

    The Items collection of a combobox is of type ObjectCollection, so when you set an item with

    comboBox1.Items.Add(type1); 
    

    you are adding a RequestType object to the collection.
    Now, when you want to retrieve a single selected item from that collection, you could use a syntax like this

    RequestType t = comboBox1.SelectedItem as RequestType;
    

    Theoretically, (when you have complete control on the adding of the combobox items) you could avoid to check if the conversion applied with the as keyword was successful, but this is not the case because the SelectedItem could be null and therefore it is always a good practice to test with

       if(t != null)
       {
           Console.WriteLine(t.Value + " " + t.Text);
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this form which allows the input of any product quantity from 1-10:
I have a form and from this I call dialogPrintDiet.ShowDialog() which launchs my dialog.
I have a form which will include some optional questions that need to asked
I have a SQL Server 2008 database which contains data that I need to
I have a spinner which is populated from the database. This in turn is
I have this html form which has options: <tr> <td width=30 height=35><font size=3>*List:</td> <td
In my c# application i have this small form which is used to set
I have this form tag below where the form submits to itself which I
I have an input which is of this form: (((lady-in-water . 1.25) (snake .
I have a number which is in this form : 2012-01 (2012 as current

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.