I have a ComboBox already populated, and all I want to do is set it to a specific selectedItem, knowing its value.
I am trying to do this, but nothing happens:
comboPublisher.SelectedValue = livre.Editeur;
Given the fact that I already applied the Equals (..) method in my Editeur class, as follows:
public bool Equals(IEditeur editeur) { return (this.Nom == editeur.Nom); }
This is how I populate my ComboBox:
foreach (Business.IEditeur editeur in _livreManager.GetPublishers()) { comboPublisher.Items.Add(editeur); }
Any idea?
Thanks!
[EDIT]: this seems to work with:
comboPublisher.SelectedItem = livre.Editeur;
My Equals Method:
public override bool Equals(object obj) { IEditeur editeur = new Editeur(); if (!(obj is System.DBNull)) { editeur = (IEditeur)obj; return (this.Nom == editeur.Nom); } return false; }
c # combobox
Amokrane chentir
source share