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