Skip to content

Updating combobox if the ToString() result of an item changes

Valter

Asked Jun 6, 2010, 5:38 AM EDT1 answer
Share
LinkedInX
Hello,
I've got a simple question related to combobox. Consider that a combobox is populated with the instances of the following example class:
C#
class Plot
{
  private string label;

  public string Label
  {
    get { return label; }
    set { label = value; }
  }

  public override string ToString()
  {
    return label;
  }
}

Now consider that one of these objects will be assigned a different label somewhere else in the program. How can I notify the combobox that it should call the ToString() method of this item again to update its list accordingly? I hope there exists some intelligent mechanism, I'd like to avoid just manually repopulating the combobox each time an item label is changed.

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Figured out a solution myself. I just have to reassign this item that has changed:
    comboBox1.Items[n] = item
    0