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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:09:28+00:00 2026-06-04T01:09:28+00:00

As far as I know, combo-boxes in Windows Forms can only hold one value.

  • 0

As far as I know, combo-boxes in Windows Forms can only hold one value. I needed a text and an Index so i created this little class:

public class ComboboxItem { 
    public string Text { get; set; } 
    public object Value { get; set; } 
    public override string ToString() 
    { 
        return Text; 
    }
}

I add an Item to the combo-box as following:

ComboboxItem item = new ComboboxItem()
{
    Text = select.Item1,
    Value = select.Item2
};

this.comboBoxSelektion.Items.Add(item);

Now to my question: How do I set the combobox to specific item?
I tried this, but that didn’t work:

this.comboBoxSelektion.SelectedItem = new ComboboxItem() { Text = "Text", Value = 1};
  • 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-04T01:09:30+00:00Added an answer on June 4, 2026 at 1:09 am

    The last code sample you provided doesn’t work, because the item in the ComboBox and the item you create via new are different instances (= memory references) which are not the same (two different memory pointers) even though they are equal (their members have the same values). Just because two objects contain the same data doesn’t make them the same object – it makes them two different objects that are equal.

    That’s why usually there’s a big difference between o1 == o2 and o1.Equals(o2);.

    Examples:

    ComboboxItem item1 = new ComboBoxItem() { Text = "Text", Value = 1 };
    ComboboxItem item2 = new ComboBoxItem() { Text = "Text", Value = 1 };
    ComboboxItem item3 = item1;
    
    item1 == item2      => false
    item1.Equals(item2) => true, if the Equals-method is implemented accordingly
    item1 == item3      => true!! item3 "points to the same object" as item1
    item2.Equals(item3) => true, as above
    

    What you need to do is find the same instance you added to the list. You could try the following:

    this.comboBoxSelektion.SelectedItem = (from ComboBoxItem i in this.comboBoxSelektion.Items where i.Value == 1 select i).FirstOrDefault();
    

    This selects the first item from the items assigned to the ComboBox the value of which is 1 and sets it as the selected item. If there’s no such item, null is set as the SelectedItem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As far as I know, only the convenience methods return created objects with an
so far i only know to use Ctrl-Shift-A to do SVN in TextMate. is
As far as I know document.getElementById('myId') will only look for HTML elements that are
As far as I know both FireFox and Safari can not work with Kerberos
So far I know, the conditional comments are only supported for different Versions of
So far I know two ways to pass php variables to javascript. One is
so far i know of ab and httperf, both can check the performance of
I am new to Octave/Matlab so so far I know, you can apply matrix
As far as know, I must be careful with PHP, and I think Javascript.
As far as i know, there is no direct equivalent in C#. My 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.