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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:02:35+00:00 2026-05-16T16:02:35+00:00

I am experiencing some problems while working with ComboBox. The display member for my

  • 0

I am experiencing some problems while working with ComboBox.

The display member for my combobox is not being populated by the overridden ToString method of class MAP.

Here is my code:

Form1.cs:

private void Form1_Load(object sender, EventArgs e) {  
    ...  
    ...      
    MAPList MAP = new MAPList();  
    comboBox1.DataSource = MAP.All;  
    comboBox1.ValueMember = "Code";  
    ...  
    ...  
}

MAPList.cs:

public class MAPList {  
    public readonly List<MAP> All;

    public MAPList() {
        All = new List<MAP>();

        var MapData = // Getting map data

        foreach(MAP m in MapData) {
            All.Add(new Map(m.Name, m.Code));
        }
    }
}

MAP.cs:

public class MAP {
    public readonly string Name;

    private string code;
    public string Code { get { return code; } }

    public RadioCode(string Name, string Code) {
        this.Name = Name;
        this.code = Code;
    }

    public override string ToString() {
        return String.Format("{0}: {1}", Name, Code);
    }
}
  • 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-16T16:02:35+00:00Added an answer on May 16, 2026 at 4:02 pm

    ToString will not be called if you set ValueMember. If you do not set ValueMember it will work as expected but then of course Code will not be used as the selected value of the ComboBox.

    Alternatively, if you wish to use ValueMember you may also want to set DisplayMember. You can create a property on your MAP that is used for display, i.e.:

    public class MAP
    {
        public readonly string Name;
    
        private string code;
    
        public string Code { get { return code; } }
        public string Display { get { return ToString(); } }
    
        public MAP(string Name, string Code)
        {
            this.Name = Name;
            this.code = Code;
        }
    
        public override string ToString()
        {
            return String.Format("{0}: {1}", Name, Code);
        }
    }
    

    In the form you can then set DisplayMember:

    MAPList MAP = new MAPList();
    comboBox1.DataSource = MAP.All;
    comboBox1.ValueMember = "Code";
    comboBox1.DisplayMember = "Display";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am experiencing some problems while setting ValueMember property of my ComboBox. The line
I am working on an Orbited -powered website and I'm experiencing some annoying behavior
Our team has been experiencing a recurring problem with velocity templates. Upon rendering, some
We are experiencing some slowdowns on our web-app deployed on a Tomcat 5.5.17 running
Wanting to implement authentication by client certificates I am experiencing some issues. First some
After experiencing numerous problems with a certain media player, it got me thinking is
I'm working on a large-size dual AS3/Flex project (some parts are pure AS3, other
I'm working on an application I received from a client and they've used some
Im experiencing problem with webclient to parse some very sensitive webpage. Somehow, webclient failed
I'm experimenting with some multithreading constructions, but somehow it seems that multithreading is not

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.