Hi,
we encountered the same problem and this is how we managed to populate correctly the combobox.
Imagine you have a class named Dog_Race
The class contain some arguments
public string race_name
public int race_id
Your constructor looks like that
public Dog_Race()
{
}
You have to create another constructor
public Dog_Race(int idrace, string namerace)
{
this.race_name=namerace;
this.race_id = idrace;
}
Now, you have to create getter and setter
public int getIdRace()
{
return(this.race_id);
}
public string getNameRace()
{
return(this.race_name);
}
public override string ToString()
{
return this.getNameRace();
}
That's for the Dog_Race class
Now, how to populate the combobox using it :
//for example
MyCombobox.items.add(new Dog_Race(0,'MyRaceName'));
And, how to get the values from Combobox
int dograceid = ((Dog_Race)MyCombobox.selectedItem).getIdRace();
int dogracename = ((Dog_Race)MyCombobox.selectedItem).getNameRace();
Hope it'll help you
|