I have a listbox on a container control. On the container I have an event definition PropertyChanged. I want to raise this event when the listbox CellTextChange event is raised. If I try to raise this event in the CellTextChange event of the listbox I get the error ‘This item does not exist’.
So if anyone else needs a solution, the way I did this was to have computed properties on the container. These are set from the listbox. In the set of the computed, the event is raised.
A method, in my opinion, could be more appropriated. Something like:
Class ContainerControl1 // Container with a listBox
Inherits ContainerControl
//Define ContainerControl1.Events.MyChangedEvent(): // New Event Definition
Public Event MyChangedEvent()
//Define ContainerControl1.Methods.RaiseMyChangedEvent(): // A method used just to raise my Event
Sub RaiseMyChangedEvent()
RaiseEvent MyChangedEvent // Fire my new Event
End Sub
//Define ContainerControl1.Listbox1.Events.Change(): // Let's fire MyChangedEvent when ListBox Change Event fires
Sub Change() // The change Event from the contained ListBox
RaiseMyChangedEvent() // Tell the container to fire my event
End Sub
End Class
As Rick has pointed out, Raising Events in a Container isn’t so hard to do. I rely on this functionality for a LOT of our projects. We are big fans of Containers to make UI modular and easier to code.
[quote=115708:@Mike Charlesworth]Ok sorted it. Thanks
So if anyone else needs a solution, the way I did this was to have computed properties on the container. These are set from the listbox. In the set of the computed, the event is raised.[/quote]
Really no need
If you have a container that contains a listbox and the container has an event definition, Foo, then in the listbox you can raiseEvent Foo
When you drop an instance of this container on a layout you can then implement the Foo event
True. There is no need to try to bubble the event out, it’s already there.
Class ContainerControl1 // Container with a listBox
Inherits ContainerControl
//Define ContainerControl1.Events.MyChangedEvent(): // New Event Definition
Public Event MyChangedEvent()
//Define ContainerControl1.Listbox1.Events.Change(): // Let's fire MyChangedEvent when ListBox Change Event fires
Sub Change() // The change Event from the contained ListBox
RaiseEvent MyChangedEvent // Fire my new Event
End Sub
End Class
Thanks guys, I thought it worked too. I have done it this way in the past and had no problem. Rick your example works fine and as I wanted. I have just tried to recreate what I did this morning and no problem it works fine. I cant explain it but it is working fine now. I must have done something wrong but cant see what now.
Does that then mean Eli’s quote below is incorrect?
Class ContainerControl1 // Container with a listBox
Inherits ContainerControl
//Define ContainerControl1.Events.MyChangedEvent(): // New Event Definition
Public Event MyChangedEvent()
//Define ContainerControl1.Listbox1.Events.Change(): // Let's fire MyChangedEvent when ListBox Change Event fires
Sub Change() // The change Event from the contained ListBox
RaiseEvent MyChangedEvent // Fire my new Event
End Sub
End Class
The container is itself a class. The change() method is in the ContainerControl1 Class level and the raise ocurred there.
Class ContainerControl1 // Container with a listBox
Inherits ContainerControl
//Define ContainerControl1.Events.MyChangedEvent(): // New Event Definition
Public Event MyChangedEvent()
//Define ContainerControl1.Listbox1.Events.Change(): // Let's fire MyChangedEvent when ListBox Change Event fires
Sub Change() // The change Event from the contained ListBox
RaiseEvent MyChangedEvent // Fire my new Event
End Sub
End Class
The container is itself a class. The change() method is in the ContainerControl1 Class level and the raise ocurred there.[/quote]
I see, thanks Rick