C # - How to get a link to an object from a combo box?

I populate a ComboBox in C # from an instance of a class. How to get the selected item by receiving a link to the corresponding object? I have already used SelectedValue, SelectedItem, SelectedIndex, but they all return a string representation of my object.

thank

[EDIT]

Part of the code to show what I'm trying to do:

The filling part:

foreach (Business.IAuteur auteur in _livreManager.GetAuthors())
            {
                comboAuthor.Items.Add(auteur);
            }

The receiving part is activated when the save button is pressed:

 private void btnSave_Click(object sender, EventArgs e)
        {
            Business.IAuteur auteur = new Business.Auteur();

            auteur = (Business.IAuteur)comboAuthor.SelectedValue;

            // A short verification that my item has been correctly
            // retrieved
            toolStripStatusLabel1.Text = auteur.Nom;
        }

Error message indicating here: toolStripStatusLabel1.Text = auteur.Nom;

The reference to the object is not set to the instance of the object.

+3
source share
1 answer

SelectedItem string, ComboBox . ToString POCOs, ComboBox , SelectedItem.

MSDN, Equals POCO, Items, .

: .
.ToString() ComboBox .

+5

Source: https://habr.com/ru/post/1734591/


All Articles