Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted (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 by georg
Posted

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

Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...