Help on Adding tree node ??

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • serge calderara

    #1

    Help on Adding tree node ??

    Dear all,

    I have an application which timely create log file in XML format
    I ma using the SystemFileWatch er object to monitor creation of new file in
    the proper path. So far no problem

    When the first file is created, my SystemFile onchanged event is catch and
    then I add the new log file in a treview control with the following code:

    Dim m_Root As New TreeNode
    m_Root = Me.tLogView.Nod es.Item(0)
    'For idx = 0 To sFile.Count - 1
    Dim m_Node As New TreeNode(e.Name , 2, 2)
    m_Root.Nodes.Ad d(m_Node)
    m_Root.Nodes.Ad d(m_Node)

    When the second file is created, event is cacthed again, and I am suppose to
    add the new file to the treeview as previous step. But at that time I have an
    exception which says something like I am not in the current thread and I need
    to call Control.Invoke before adding my new node ???

    What sors it means ? how can add new nodes when Onchange event occurs?

    thaks for your help
    regards
    serge
  • Dave

    #2
    Re: Help on Adding tree node ??

    The Control class requires methods to be invoked on the thread in which the Control was created. The event that is being handled
    (your "OnChanged" event) is running on a thread-pooled thread.

    Do something like this (sorry that my VB isn't very good):

    Private Delegate AddNodeInvoker( Name as String)

    Public Sub OnChanged(sende r as Object, e As EventArgs)
    If Me.tLogView.Inv okeRequired Then
    Dim _AddNode As New AddNodeInvoker( AddNode)
    Dim Params As New Object(1)
    Params(0) = e.Name
    Me.tLogView.Inv oke(_AddNode, Params)
    Else
    AddNode(e.Name)
    End If
    End Sub

    Private Sub AddNode(Name as String)
    Dim m_Root As New TreeNode
    m_Root = Me.tLogView.Nod es.Item(0)
    'For idx = 0 To sFile.Count - 1
    Dim m_Node As New TreeNode(Name, 2, 2)
    m_Root.Nodes.Ad d(m_Node)
    m_Root.Nodes.Ad d(m_Node)
    End Sub

    --
    Dave Sexton
    dave@www..jwaon line..com
    -----------------------------------------------------------------------
    "serge calderara" <sergecalderara @discussions.mi crosoft.com> wrote in message
    news:A6CAF317-3B51-407B-A2CA-402264365BD4@mi crosoft.com...[color=blue]
    > Dear all,
    >
    > I have an application which timely create log file in XML format
    > I ma using the SystemFileWatch er object to monitor creation of new file in
    > the proper path. So far no problem
    >
    > When the first file is created, my SystemFile onchanged event is catch and
    > then I add the new log file in a treview control with the following code:
    >
    > Dim m_Root As New TreeNode
    > m_Root = Me.tLogView.Nod es.Item(0)
    > 'For idx = 0 To sFile.Count - 1
    > Dim m_Node As New TreeNode(e.Name , 2, 2)
    > m_Root.Nodes.Ad d(m_Node)
    > m_Root.Nodes.Ad d(m_Node)
    >
    > When the second file is created, event is cacthed again, and I am suppose to
    > add the new file to the treeview as previous step. But at that time I have an
    > exception which says something like I am not in the current thread and I need
    > to call Control.Invoke before adding my new node ???
    >
    > What sors it means ? how can add new nodes when Onchange event occurs?
    >
    > thaks for your help
    > regards
    > serge[/color]


    Comment

    Working...