|
-
Mar 29th, 2003, 02:00 AM
#1
Thread Starter
Frenzied Member
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.
-
Mar 29th, 2003, 06:23 AM
#2
Lively Member
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.
-
Mar 29th, 2003, 03:49 PM
#3
Thread Starter
Frenzied Member
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.
-
Apr 3rd, 2003, 11:23 AM
#4
Thread Starter
Frenzied Member
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:
'Declare these module level variables:-
Dim msSearchList As String
Dim mcolSearchKeys As Collection
'After populating the treeview, issue these commands:-
Set mcolSearchKeys = New Collection
msSearchList = CreateSearchList(tvw.Nodes(1).Root)
'Add in these procedures:-
Private Function CreateSearchList(nodeStart As Node) As String
Dim sList As String
sList = ""
Do
sList = sList & UCase(Left(nodeStart.Text, 1))
mcolSearchKeys.Add nodeStart.Key
If nodeStart.Children > 0 Then
sList = sList & CreateSearchList(nodeStart.Child)
End If
Set nodeStart = nodeStart.Next
Loop While Not nodeStart Is Nothing
CreateSearchList = sList
End Function
Private Sub tvw_KeyPress(KeyAscii As Integer)
Dim sSelectedKey As String
Dim lIndex As Long
Dim lCharIndex As Long
sSelectedKey = tvw.SelectedItem.Key
For lIndex = 1 To mcolSearchKeys.Count
If mcolSearchKeys.Item(lIndex) = sSelectedKey Then
Exit For
End If
Next
lCharIndex = InStr(lIndex + 1, msSearchList, UCase(Chr(KeyAscii)))
If lCharIndex = 0 Then
lCharIndex = InStr(1, msSearchList, UCase(Chr(KeyAscii)))
End If
tvw.Nodes(mcolSearchKeys.Item(lCharIndex)).Selected = True
KeyAscii = 0
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|