[RESOLVED] [Help] TreeView_KeyPress? No detection of Delete Key?
Im trying to use the Delete key to set off the treeview_keypress sub however it appears to do absolutly nothing when I hit any key thats not a letter.
Is there a quick fix for this?
EDIT:I resolved this Simply by changing from keypress to keyup. However Im not sure How to remove the selected node? Il google However helps appreciated :) Thanks
Ahh well this was a pointless post Im going to repost a new question :| I figured all the treeview stuff out in about 20 mins lol except for one thing.
Re: [RESOLVED] [Help] TreeView_KeyPress? No detection of Delete Key?
It's always a good idea to post your solution - rememebr that this is public forum and many people come here to get their aswers.
Anyway, if anyone's wondering how node can be removed here is a quick example:
Code:
Option Explicit
Private Sub Form_Load()
With TreeView1
.Style = tvwTreelinesPlusMinusPictureText
.Nodes.Add , , "R", "Root"
.Nodes.Add "R", tvwChild, , "Child1"
.Nodes.Add "R", tvwChild, , "Child2"
.Nodes.Add "R", tvwChild, , "Child3"
.Nodes.Add "R", tvwChild, , "Child4"
.Nodes.Add "R", tvwChild, , "Child5"
.Nodes("R").Expanded = True
End With
End Sub
Private Sub TreeView1_KeyUp(KeyCode As Integer, Shift As Integer)
If Shift = 0 Then
Select Case KeyCode
Case vbKeyDelete
If Not TreeView1.SelectedItem.Key = "R" Then 'keep the root node
TreeView1.Nodes.Remove TreeView1.SelectedItem.Index
End If
End Select
End If
End Sub
Re: [RESOLVED] [Help] TreeView_KeyPress? No detection of Delete Key?
-- "vbKeyDelete" := Is what, I think that what your after??? Also have .KeyPreview = True, in the properties for the Form, and even if it appears in the Control, have that too selected, as well. I cannot remember if that appears in a TreeView in VB6. Also try a Context Menu, that is attached to the TreeView, that would have better results to the Control's process of things??? But that would only be a suggestion, and then not follow me if you don't want to...
About your Delete key not working: := Try using the Shift process inaddition to the KeyCode process. Maybe that it would work be using that process, and then see what happens. If so then trap that to not execute...