Raised Event Bypassed

georg

Freshman
Joined
Jun 26, 2003
Messages
28
Location
Australia
Hello All,

I am having trouble raising an event in class "a" and handling it in class "b".

When my code gets around to the raise event statement (in class "a") the debugger just moves over it and on to the next line of code, without raising any type of error.

Has anyone else seen this/knows what is going on?

Thanks,

georg
 
Thanks for the interest guys.

Ok, the situation is a bit more complex than I originally stated.

- Creating a datagrid programmatically
- Datagrid has 4 combo boxes also created programmatically.
- Project at this stage has a number of classes in a number of modules
- I have 1 class for the combo box column Public Class DataGridComboBoxColumn (Inherits DataGridTextBoxColumn) object ...
- and another for the datagrid object: Public Class DataGridCoW (Inherits DataGrid).
- When I need to respond to a changed event in the combo box, it seems best to do it in the Combo Box class, raise a custom event and then deal with this in the Datagrid class.

I'm happy to simply call a proc in the DataGridCoW class, but I can't work out how to do this either.

As you can see I am new to OO, and wondering if my approach is just mangled procedural code for OO.

Class "a" (a Component)
Visual Basic:
Public Class DataGridComboBoxColumn
Public Event LeavingHowPaid As DataGridComboBoxLeaveEventHandler
AddHandler ColumnComboBox.Leave, New EventHandler(AddressOf LeaveComboBox)
  Public Sub LeaveComboBox(ByVal sender As Object, ByVal e As System.EventArgs) Handles ColumnComboBox.Leave
	   Dim sCBText As String
            sCBText = ColumnComboBox.Text
		c = Me.DataGridTableStyle.DataGrid.CurrentCell.ColumnNumber
'###this is where I try to raise the event
		If sCBText = "CHQ" Then
		RaiseEvent LeavingHowPaid(_rowNum, c ,sCBText)
        	End If
        End Sub
End class
Then in a class (not really sure why I am doing this):
Visual Basic:
Public Class Delegator
Public Delegate Sub DataGridComboBoxLeaveEventHandler(ByVal r As Integer, ByVal c As Integer, ByVal sHowPaid As String)
End class
Then in Class "b" (a Component):
Visual Basic:
    Public Class DataGridCoW
        Inherits DataGrid
        Private WithEvents _cbc As DataGridComboBoxColumn
        Private Sub _cbc_LeavingHowPaid(ByVal r As Integer, ByVal c As Integer, ByVal sHowPaid As String) Handles _cbc.LeavingHowPaid
            MessageBox.Show(sHowPaid)
        End Sub
End class
The object DataGridComboBoxColumn was instansiated in another class, and added to the datagrid.

Just thinking about this has given me a few ideas for testing, so I may come back with a bit more information.

Thanks,

georg
 
Last edited:
Perhaps I've missed it in your code but you don't appear to be telling class b to handle the event.

ps if you wrap you code in [ vb ] [ /vb ] but remove the spaces the forum will format up the code and make it easier to read.
 
PlausiblyDamp: Thanks for the tip on the HTML .
How would I tell class b to handle the event.?

Heiko: I'm pretty sure that I have both of the elements that you suggested.

georg
 
Credit to PlausiblyDamp!

(And maybe the 1 hour of (ocean) surfing to clear my head.)

My addhandler statement (when I instansiated the Class DataGridComboBoxColumn) wasn't telling Class "b" to handle the event .

Thanks.

georg.
 
Back
Top