3 levels event handling help...

jerry_hokh

Active member
Joined
Mar 14, 2006
Messages
25
Programming Experience
1-3
Hi guys,

pls help me out of this....

I have 3 classes, Report, Row and Cell

Report has a collection of Row (10 rows), 1 ROW as 1 Cell (in my example)

What i want is: when I change height in Cell , the Row's height is change and the Report's height also change.

*** My probs: my row's height is changed based on my Cell height but my report height is UNCHANGED.

thank you a lot for any help.

Please take a look at my code:

******************** REPORT ****************************
Public Class Report
Private WithEvents row As Row
Public rowlist As New ArrayList
Public height As Integer = 0

Public WithEvents MyCell As System.Windows.Forms.TextBox = New System.Windows.Forms.TextBox()

Public Sub New()
For i As Integer = 0 To 9
row = New Row
rowlist.Add(row)
Next


End Sub

Private Sub row_RowHeightChange(ByVal sender As Object, ByVal e As AddEventArgs) Handles row.RowHeightChange
height = e.height
End Sub
End Class

*********************** ROW ****************************
Public Class Row
Public WithEvents MyCell As Cell
Public _height As Integer = 0
Public Event RowHeightChange(ByVal sender As Object, ByVal e As AddEventArgs)

Public Sub New()
End Sub

Public Property Height() As Integer
Get
Return _height
End Get
Set(ByVal value As Integer)
_height = value
Dim e1 = New AddEventArgs(Height)
RaiseEvent RowHeightChange(Me, e1)
End Set
End Property

Public Property Cell() As Cell
Get
Return MyCell
End Get
Set(ByVal value As Cell)
MyCell = value
End Set
End Property
Private Sub MyCell_Add(ByVal sender As Object, ByVal e As AddEventArgs) Handles MyCell.Add
Height = e.height
Me.Height = Height

End Sub
End Class

************************** CELL *********************
Public Class Cell
Public _height As Integer
Public Event Add(ByVal sender As Object, ByVal e As AddEventArgs)
Public Property Height() As Integer
Get
Return _height
End Get
Set(ByVal value As Integer)
_height = value
Dim e = New AddEventArgs(_height)
RaiseEvent Add(Me, e)

End Set
End Property

End Class

*********************** AddEventArgs ********************
Public Class AddEventArgs
Inherits System.EventArgs
Public height As Integer
Public Sub New(ByVal h As Integer)
Me.height = h
End Sub
'Provide one or more constructors, as well as fields and
'accessors for the arguments.
End Class
 
try in report class:
- remove 'WithEvents' for row declare.
- in sub new for loop:
row = New Row
addhandler row.RowHeightChange, addressof row_RowHeightChange
rowlist.Add(row)
 
Back
Top