Hi Edhy, Thank you for you help! the code for the LoadMsg and also the code for the BO event as bellow. I think the main problem is how to refresh the parentform control through chilform. If the FrmMain Activated, I call the LoadMsg on the FrmMain treeview data refreshed.
Public Sub SystemMsgBO_ServerDataChanged(ByVal e As System.Data.SqlClient.SqlNotificationEventArgs) Handles Me.ServerDataChanged
'-- Show the query information to make sure it had been executed
MsgBox(e.Info.ToString() & ControlChars.CrLf & e.Source.ToString() & ControlChars.CrLf & e.Type.ToString())
FrmMain.LoadMsg()
End Sub
'the following code in FrmMain
#Region "Load MessageTree"
Private Sub LoadMsg()
'-- Establish Locals
Dim loMsgNode As TreeNode
'-- Clear the tree
CheckedTreeView2.Nodes.Clear()
Dim MyMsgBo As New SystemMsgTitleBO
Dim loParentID As String
MyMsgBo.FillDataTable("select * from SystemMessageTitle" )
'-- Cycle through all of the parent records
If MyMsgBo.MoveFirst() Then
Do
'-- Create the new root node
loMsgNode = New TreeNode(MyMsgBo.MsgCategory)
loParentID = MyMsgBo.MsgCategory
'-- Load any children nodes
LoadMsgChildNodes(loParentID, loMsgNode)
Me.CheckedTreeView2.Nodes.Add(loMsgNode)
Loop While MyMsgBo.MoveNext()
End If
'-- Expand and show the last node
Me.CheckedTreeView2.ExpandAll()
Me.CheckedTreeView2.SelectedNode = CheckedTreeView2.Nodes(0)
End Sub
Private Sub LoadMsgChildNodes(ByVal ParentID As String, ByVal ParentNode As TreeNode)
'-- Establish Locals
Dim loMsgNode As TreeNode
'-- Load the child records
Dim loChildMsgBO As New SystemMsgBO
loChildMsgBO.FillDataTable("select * from SystemMessage where MsgCategory='" & ParentID & "' and postto='All' or postto='" & SecurityBasics.CurrentUser.UserName & "'")
'-- Cycle through the child nodes
If loChildMsgBO.MoveFirst() Then
Do
'-- Create the node
loMsgNode = New TreeNode(loChildMsgBO.MsgDetail)
loMsgNode.Tag = loChildMsgBO.MsgCategory
'-- Add to parent nodes
ParentNode.Nodes.Add(loMsgNode)
Loop While loChildMsgBO.MoveNext()
End If
'-- Clean Up
loChildMsgBO.Dispose()
End Sub
#End Region