views:

139

answers:

1

Hello,

I'm interested in creating combo boxes that represent many-to-many relationship. That is if one combobox changes selection that would trigger the other combobox to change content, and vice versa. Anybody knows how to do it in Silverlight?

I tried it, but I either get SelectedItem reset in the second combobox when I change the value in the first, or I basically get an infinite loop of Collection1Changed -> Collection1SelectionChanged -> Collection2Changed -> Collection2SelectionChanged -> Collection1Changed -> ...

Anybody knows of a good technique?

A: 

One potential solution is to detach and reattach the event handlers, i have no idea if this is a good idea or not though, there is probably a better better method!

private void Collection1_SelectionChanged (object sender, eventargs e)
{
    Collection2.SelectionChanged -= Collection2_SelectionChanged; //drop event handler
    //make changes...
    Collection2.SelectionChanged += Collection2_SelectionChanged; //add event handler
}

This seems like a pretty crazy method, but it's all i can think of atm!

Paul Creasey