StrataFrame Forum

How to update parent Form Treeview or other control?

http://forum.strataframe.net/Topic25466.aspx

By Amy Tai - 1/3/2010

Dear Sir/Madam

        I have a problem about how to refresh the parent form treview data. In my program, When SQL table updated, In my Bo the ServerData changed Event received the notification. So I call  FrmMain.LoadMsg() to refresh the treeview data in Bo ServerDataChanged Event. I found the FrmMain.LoadMsg is running but the FrmMain's treeview not refresh. please told to me how to apply this function. (I using VB.net) , Thanks a lot.

    Private Sub SystemMsgBO_ServerDataChanged(ByVal e As System.Data.SqlClient.SqlNotificationEventArgs) Handles Me.ServerDataChanged

          MsgBox(e.Info.ToString() & ControlChars.CrLf & e.Source.ToString() & ControlChars.CrLf & e.Type.ToString())

           FrmMain.LoadMsg()

End Sub

By Trent L. Taylor - 1/3/2010

Just so that understand what you are trying to accomplish, are you trying to use the SQL Server query notifications to alert you of a change within your SQL Query so that you can refresh your treeview?
By Les Pinter - 1/3/2010

Dear Amy,

   My question is the same as Trent's: Do you want your program to detect a change in the SQL tables made by another user and update the treeview automatically, or do you want to refresh the treeview when you make changes to the table from within your own program?

Les

By Amy Tai - 1/3/2010

Hi Trent & Les,

  Thanks your respond.           
   I already enabled SQL Broker service and receive the query notifications from SQL Server in BO ServerDataChange Event, So I want to refresh the treeview (in Mainform ), I do that but found the treeview data not updated.
   I want to refresh treeview data in BO ServerDataChange Event directly, and I have a procdure name LoadMsg() in MainForm to populate the treeview data. My questions is: Can I call LoadMsg() in BO directly to refresh treeview? or need using other method to refresh parentForm treeview data?

By Edhy Rijo - 1/4/2010

Hi Amy,



I have not used SQL Broker services yet but I believe all you have to do is after you get your notification, fill up the BO that is loading the Treeview and then refresh the Treeview.
By Amy Tai - 1/4/2010

Hi Edhy,

 
        yes, just what you said. but my problem is the treeview data not update on the screen. I had refresh it but nothing changed until I click the button on the mainform when it activate . If i call the button (LoadMsg) in BO directly, it don’t work.

 

By Edhy Rijo - 1/4/2010

Amy Tai (01/04/2010)
... yes, just what you said. but my problem is the treeview data not update on the screen. I had refresh it but nothing changed until I click the button on the mainform when it activate . If i call the button (LoadMsg) in BO directly, it don’t work.



Hi Amy,

The refresh have to happen in the form where the treview is, not in the BO. So just to be clear:

1. You have a form with a treeview and a BO instance with the data for the treeview.

2. You setup the Broker service and in the BO instance in the form, you receive notification of data changes.

3. In the event where this notification is receive, you then call the LoadMsg method in the form to refresh your treeview.



If the above is correct, please post the code for the LoadMsg and also the code for the BO event where the SQL notification is received.
By Amy Tai - 1/4/2010

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

By Amy Tai - 1/5/2010

Dear All,

         I solved, just using this code:  CType(StrataFrameApplication.MainForm, FrmMain).LoadMsg() , It's work.

By Edhy Rijo - 1/5/2010

Glad you find the solution.



Also take a look at the BO.GetEnumerable() which allow you to loop the BO records in a better fashion than the DO WHILE. Search the forums for GetEnumerable() samples and also the SF help file.
By Trent L. Taylor - 1/7/2010

Thanks, Edhy. Glad you found a solution. Wink