Results 1 to 4 of 4

Thread: TreeView anomaly [Resolved]

  1. #1

    Thread Starter
    Frenzied Member blindlizard's Avatar
    Join Date
    Feb 2001
    Location
    Austin, TX - United States of America
    Posts
    1,141

    Thumbs up TreeView anomaly [Resolved]

    Let me see if I can even ask this question. I have a TreeView Control. On that control lets say I have nodes like this:
    Code:
    A
    |---B
    |    |-----C
    |    |-----D
    |    |-----E
    |---F
    Ok, now when the form Loads A is selected, and the control has focus. I hit B on my key board and it jumps to B, I hit C and it jups to C, I hit F and it jumps to F, then I hit A and it jumps to A. That is all fine, as long as I am hitting one up or down a level in the hierarchy, all is well. Now the problem is, if C is selected and I hit D, it moves to D, but them if I hit E, nothing happens. If I click on D (which is already selected) and then hit E, it moves. However if I then hit D or C, or any other letter (A, B, F) it won't move. I have to click on E first to get it to move.

    I hope you can understand what I am saying.
    Last edited by blindlizard; Apr 3rd, 2003 at 11:23 AM.
    I drink to make other people more interesting!
    [vbcode]On Error GoTo Bar[/vbcode]
    http://www.monsterlizard.com

  2. #2
    Lively Member
    Join Date
    Feb 2001
    Posts
    78
    I just checked this out an I find the same thing, that it gets stuck occasionally. I didnt find a solution - I tried reselecting the treeview in the keypress event but It didnt work. Im sure there must be some work around.

  3. #3

    Thread Starter
    Frenzied Member blindlizard's Avatar
    Join Date
    Feb 2001
    Location
    Austin, TX - United States of America
    Posts
    1,141

    Thumbs up

    Yeah it is really strange. The problem I have is that I may have hundreds of nodes in the same branch, and I need the user to beable to just go right to the one they want. Scrolling sucks. Maybe someone will know.
    I drink to make other people more interesting!
    [vbcode]On Error GoTo Bar[/vbcode]
    http://www.monsterlizard.com

  4. #4

    Thread Starter
    Frenzied Member blindlizard's Avatar
    Join Date
    Feb 2001
    Location
    Austin, TX - United States of America
    Posts
    1,141
    I did however get a work around from someone at experts-exchange:

    By phildaley @ Experts-Exchange
    I think I've found a solution for you. I create a string of the leading characters of the text of each node and a corresponding collection of the node keys. When a key is pressed, you can then lookup the corresponding node. The search list is created in such a way that it corresponds with the node order as it appears on screen. When a key is pressed, the current node is used as a start point for the search.
    VB Code:
    1. 'Declare these module level variables:-
    2. Dim msSearchList As String
    3. Dim mcolSearchKeys As Collection
    4.  
    5. 'After populating the treeview, issue these commands:-
    6. Set mcolSearchKeys = New Collection
    7. msSearchList = CreateSearchList(tvw.Nodes(1).Root)
    8.  
    9. 'Add in these procedures:-
    10.  
    11. Private Function CreateSearchList(nodeStart As Node) As String
    12.    Dim sList As String
    13.    
    14.    sList = ""
    15.    Do
    16.        sList = sList & UCase(Left(nodeStart.Text, 1))
    17.        mcolSearchKeys.Add nodeStart.Key
    18.        If nodeStart.Children > 0 Then
    19.            sList = sList & CreateSearchList(nodeStart.Child)
    20.        End If
    21.        Set nodeStart = nodeStart.Next
    22.    Loop While Not nodeStart Is Nothing
    23.    CreateSearchList = sList
    24. End Function
    25.  
    26. Private Sub tvw_KeyPress(KeyAscii As Integer)
    27.    Dim sSelectedKey As String
    28.    Dim lIndex As Long
    29.    Dim lCharIndex As Long
    30.    
    31.    sSelectedKey = tvw.SelectedItem.Key
    32.    For lIndex = 1 To mcolSearchKeys.Count
    33.        If mcolSearchKeys.Item(lIndex) = sSelectedKey Then
    34.            Exit For
    35.        End If
    36.    Next
    37.    lCharIndex = InStr(lIndex + 1, msSearchList, UCase(Chr(KeyAscii)))
    38.    If lCharIndex = 0 Then
    39.        lCharIndex = InStr(1, msSearchList, UCase(Chr(KeyAscii)))
    40.    End If
    41.    tvw.Nodes(mcolSearchKeys.Item(lCharIndex)).Selected = True
    42.    KeyAscii = 0
    43. End Sub
    I drink to make other people more interesting!
    [vbcode]On Error GoTo Bar[/vbcode]
    http://www.monsterlizard.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width