I have this Combobox filled with objects
And Upon selecting a certain object from the combobox I would like to show Text in a Textbox, but for some reason I can't get my selection through.
This is what is in my combobox:
private void showBirds()
{
cboBirds.Items.Clear();
foreach (Bird b in Bird.ReadBirdCSV(txtFile.Text))
{
cboBirds.Items.Add(b);
}
}
It basically shows the names of birds from the Objects Bird.
private void cboBirds_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
//WHAT DO I WRITE HERE TO GET txbGender TO SHOW THE GENDER?
foreach (Bird b in cboBirds.Items)
{
Console.WriteLine(b.Gender +" - " + b.Name +" - " + b.Risk + " - " +b.Reference);
}
//^This shows all info on every bird.
}
I'm sure it's really simple, I just can't seem to figure it out.
Use ComboBox.SelectedIndexChanged event
private void ComboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
if(ComboBox1.SelectedItem==null) return;
var b= (Bird) ComboBox1.SelectedItem;
if(b!=null)
Console.WriteLine(b.Gender +" - " + b.Name +" - " + b.Risk + " - " +b.Reference);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With