|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Multiple observers -- panelsan event. Here's the basic idea: MyForm contains two panels LeftPanel and RightPanel (both inherit Panel). The left one is has a treeview and the right one will have whatever depending on what is selected on the left. Both panels register with an event in MyController (something like SelectedChanged). The problem is only the left SelectedChanged is being notified of the event. Nothing happens in RightPanel at all. In panels: --------------------- private MyController.MyControllerHandler ctrlDelegate; private MyController ctrl; .... public Left(and Right)Panel() { ctrl = new MyController(); ctrlDelegate = new MyController.MyControllerHandler(this.SelectedChanged); ctrl.SelectedChanged += ctrlDelegate; ....} .... public void SelectedChanged(object sender){ //do something } --------------------- In just LeftPanel: --------------------- private void treeView_AfterSelected(object sender, TreeViewEventArgs e) { .... ctrl.SelectedIndex = something; } --------------------- In MyController: --------------------- public delegate void MyControllerHandler(object sender); public event MyControllerHandler SelectedChanged; public int SelectedIndex { set { //some stuff OnSelectedChanged(); } } public void OnSelectedChanged() { SelectedChanged(); } --------------------- Eric wrote:
> For some reason I am having a problem notifying multiple observers of So each panel has its own MyController.> an event. Here's the basic idea: > MyForm contains two panels LeftPanel and RightPanel (both inherit > Panel). The left one is has a treeview and the right one will have > whatever depending on what is selected on the left. Both panels > register with an event in MyController (something like > SelectedChanged). The problem is only the left SelectedChanged is > being notified of the event. Nothing happens in RightPanel at all. > > In panels: > --------------------- > private MyController.MyControllerHandler ctrlDelegate; > private MyController ctrl; > ... So each panel listens to the SelectedChanged event of *its own*> public Left(and Right)Panel() { > ctrl = new MyController(); > ctrlDelegate = new > MyController.MyControllerHandler(this.SelectedChanged); > ctrl.SelectedChanged += ctrlDelegate; > ...} MyController. > ... So selecting a treeview node fires the SelectedChanged event *on the> public void SelectedChanged(object sender){ > //do something > } > --------------------- > > In just LeftPanel: > --------------------- > private void treeView_AfterSelected(object sender, TreeViewEventArgs e) > { > ... > ctrl.SelectedIndex = something; > } left panel's MyController*. The right panel is listening to a completely different object's event. I can't say for sure, but it sounds like there should be only one MyController, at form level. -- Larry Lard Replies to group please |
|||||||||||||||||||||||