Results 1 to 5 of 5
  1. #1
    lmarconi is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Sep 2020
    Location
    Muscat
    Posts
    30

    How to add in a table the TreeView checked node text

    Good morning everyone. I use the following a code find in this group to check/uncheck the Parent/Children's node of my treeView and work very well.

    '------------- this is the code i use to check/uncheck the node ----------------



    Private Sub tvTreeView_NodeCheck(ByVal Node As Object)
    CheckChildAndGetNextIndex Node, Node.Checked
    End Sub

    Private Function CheckChildAndGetNextIndex(currentNode As Node, val As Boolean) As Integer
    Dim i As Integer


    currentNode.Checked = val
    CheckChildAndGetNextIndex = currentNode.index + 1


    For i = 1 To currentNode.Children
    CheckChildAndGetNextIndex = CheckChildAndGetNextIndex(tvTreeView.Nodes(CheckCh ildAndGetNextIndex), val)
    Next
    End Function

    '-------------------------------------------------------------------------------------

    My problem now is the following: for all the checked nodes (Parent and Children) I have to do some actions. My idea it was to add the selected nodes in a table and than use the table to do the actions but here is the problem: how to add the selected node text (Parent/Children) in a table (e.g. Table Name TABLE1 field1 NODE) ?

    As second problem in case i use a table, I should control also if I'm unchecking the node in order to empty the table in this case.

    If this is not the best solution, any other solution you may suggest are welcome if solve the scope.

    Thank you for usual and kindly support.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    8,980
    I would stop using tree view.
    1.it takes a programmer to make changes.
    2. it’s no longer supported in new versions of access.

    instead, use Switchboard. Make changes simply by adding/removing a value to a table.

  3. #3
    lmarconi is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Sep 2020
    Location
    Muscat
    Posts
    30
    Quote Originally Posted by ranman256 View Post
    I would stop using tree view.
    1.it takes a programmer to make changes.
    2. it’s no longer supported in new versions of access.

    instead, use Switchboard. Make changes simply by adding/removing a value to a table.
    Thank you for suggestion but at the stage of my project, i can't change it now.

  4. #4
    lmarconi is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Sep 2020
    Location
    Muscat
    Posts
    30
    Good afternoon everyone.
    Just wanted to share how i solve it.

    '-----------------------------------------
    Private Sub tvTreeView_NodeCheck(ByVal Node As Object)
    CheckChildAndGetNextIndex Node, Node.Checked
    End Sub
    '-----------------------------------------

    '-----------------------------------------
    Private Function CheckChildAndGetNextIndex(currentNode As Node, val As Boolean) As Integer
    Dim i As Integer
    Dim rst As Recordset
    Dim tm As Recordset


    currentNode.Checked = val

    If val = True Then

    Set rst = CurrentDb.OpenRecordset("tbl_Selected_Node", dbOpenDynaset)
    rst.FindFirst ("[FLOC] = '" & Left(currentNode.Text, InStr(1, currentNode.Text, " ") - 1) & "'")
    If rst.NoMatch Then
    rst.AddNew
    rst!FLOC = Left(currentNode.Text, InStr(1, currentNode.Text, " ") - 1)
    rst.Update
    End If

    Else
    Set rst = CurrentDb.OpenRecordset("tbl_Selected_Node", dbOpenDynaset)
    rst.FindFirst ("[FLOC] = '" & Left(currentNode.Text, InStr(1, currentNode.Text, " ") - 1) & "'")
    If Not (rst.NoMatch) Then
    Set tm = CurrentDb.OpenRecordset("select tbl_Selected_Node.FLOC from tbl_Selected_Node where FLOC = '" & Left(currentNode.Text, InStr(1, currentNode.Text, " ")) & "'")
    tm.Delete
    End If

    End If
    CheckChildAndGetNextIndex = currentNode.index + 1
    For i = 1 To currentNode.Children
    CheckChildAndGetNextIndex = CheckChildAndGetNextIndex(tvTreeView.Nodes(CheckCh ildAndGetNextIndex), val)
    Next

    End Function
    '------------------------------------------
    So, i add in the table "tbl_Selected_Node" every time i check the node (if is already check because part of other selection, will be bypass with the find first statement) and remove from the same table every time i uncheck the node (if is already uncheck because part of other selection, will be bypass with the find first statement).

    So far works good until i find another issue, probably because of the index of the node. Look the example below please :

    Click image for larger version. 

Name:	Hierarchy.JPG 
Views:	8 
Size:	40.0 KB 
ID:	46344


    When i check the node underline in Blue (OM.SUW.00507.CG.A18001.....) it will not check the below 3 nodes (and children). I check the index of these nodes and are not consecutive (this is what i use : CheckChildAndGetNextIndex = currentNode.index + 1) so are excluded.
    My question is, how i can manage it ? How the indexes are assigned to the hierarchy ? For your information the hierarchy is dynamic and it is build based on the parent and children located in a table.

    Hope i have been clear, if necessary i can share the code to create the dynamic hierarchy.

    Thank you,
    Cheers

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    15,722

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 12
    Last Post: 12-31-2019, 07:37 AM
  2. Replies: 7
    Last Post: 03-17-2016, 10:42 AM
  3. Replies: 7
    Last Post: 11-20-2014, 11:21 AM
  4. Replies: 1
    Last Post: 07-30-2013, 08:15 AM
  5. Display Text Only if Checkbox is Checked
    By Rick5150 in forum Forms
    Replies: 2
    Last Post: 09-16-2012, 09:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums