1

I'm trying to set multiple combo boxes to all having the same set of values to choose from (from the code side).

...
this.startTimeOptions = value;
this.cmbMonday.Items.Clear();
this.cmbTuesday.Items.Clear();

foreach (TimeObject time_option in this.TimeOptions) {
  ComboBoxItem new_item = new ComboBoxItem();
  this.cmbMonday.Items.Add(new_item);
  this.cmbTuesday.Items.Add(new_item);
} 
...

Currently when I try setting it I get this error:

"Element already has a logical parent. It must be detached from the old parent before it is attached to a new one."

So obviously they are complaining about not having a unique parent. But how do I get around this so that I have multiple comboboxes with the same list:

1
  • 1
    Create a new Item for each cbx. They can share their Values. Commented Aug 7, 2011 at 6:52

1 Answer 1

4

You need to create new ComboBoxItems for each ComboBox. Usually you would use one source collection and bind it to both ComboBoxes, they then will create the new items on their own.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.