georg Posted June 26, 2003 Posted June 26, 2003 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 Quote
JABE Posted June 26, 2003 Posted June 26, 2003 Quite difficult to tell unless we see the code. Would you mind if you post some snippets? Quote
Heiko Posted June 26, 2003 Posted June 26, 2003 Is there an event handler attached to the event in class a ? In class b, is instance of a declared with events? Quote .nerd
georg Posted June 26, 2003 Author Posted June 26, 2003 (edited) 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) 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): 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): 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 Edited June 26, 2003 by georg Quote
Administrators PlausiblyDamp Posted June 26, 2003 Administrators Posted June 26, 2003 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
georg Posted June 26, 2003 Author Posted June 26, 2003 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 Quote
georg Posted June 26, 2003 Author Posted June 26, 2003 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.