Hello,
I'm trying to dynamically populate a CheckedListBox with objects that have a string property (name) and a numeric property (id). The control populates, but displays the name of my class (testproject.Player) even though I have a ToString() method in my class.
Here's the code:
The message box returns what we expect it to ("Dan").
Any help is much appreciated.
I'm trying to dynamically populate a CheckedListBox with objects that have a string property (name) and a numeric property (id). The control populates, but displays the name of my class (testproject.Player) even though I have a ToString() method in my class.
Here's the code:
Code:
//Class definition
public class Player
{
public string playername;
public int playernbr;
public Player(string name,int id)
{
this.playername = name;
this.playernbr = id;
}
public string ToString()
{
return this.playername;
}
}
//Control population
Player p = new Player("Dan",0);
MessageBox.Show(p.ToString());
clbPlayers.Items.Add(p,false);
The message box returns what we expect it to ("Dan").
Any help is much appreciated.