Treeview control questions


1st Question:

How can I arrange my Treeview control to fire the
treeview1_NodeClick event on a dbl. click only.
Single click should only select the item (node).

2nd Question:

Can anyone please provide me with a function that can do the
following...

I wish to pass this function a node, and for the function
to remove it from the treeview, however, doing the following
test.
If no more children exist for the parent node, remove parent.

IE.

Parent A
  Child A
  Child B

User selected Child B to be removed.
I pass the corresponding node to the function and it removes
Child B only. Child A still exists, therefore function should not
remove parent. But, if user then selects Child A to be removed,
Parent A now no longer has any children, therefore, Parent A
should be removed as well.

Thank you ever so much.



vip110598Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

twardCommented:
Try this:

***** Begin Project1.vbp *****
Type=Exe
Form=Form1.frm
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#..\SYSTEM\StdOle2.Tlb#OLE Automation
Object={6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.3#0; COMCTL32.OCX
IconForm="Form1"
Startup="Form1"
Command32=""
Name="Project1"
HelpContextID="0"
CompatibleMode="0"
MajorVer=1
MinorVer=0
RevisionVer=0
AutoIncrementVer=0
ServerSupportFiles=0
VersionCompanyName="Micrographic Specialties, Inc"
CompilationType=0
OptimizationType=0
FavorPentiumPro(tm)=0
CodeViewDebugInfo=0
NoAliasing=0
BoundsCheck=0
OverflowCheck=0
FlPointCheck=0
FDIVCheck=0
UnroundedFP=0
StartMode=0
Unattended=0
Retained=0
ThreadPerObject=0
MaxNumberOfThreads=1

[MS Transaction Server]
AutoRefresh=1
***** End Project1.vbp *****

***** Begin Form1.frm *****
VERSION 5.00
Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCT2.OCX"
Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.3#0"; "COMCTL32.OCX"
Begin VB.Form Form1
   Caption         =   "Form1"
   ClientHeight    =   3195
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   ScaleHeight     =   3195
   ScaleWidth      =   4680
   StartUpPosition =   3  'Windows Default
   Begin ComctlLib.TreeView TreeView1
      Height          =   2535
      Left            =   240
      TabIndex        =   2
      Top             =   600
      Width           =   2415
      _ExtentX        =   4260
      _ExtentY        =   4471
      _Version        =   327682
      LabelEdit       =   1
      Style           =   7
      Appearance      =   1
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private lFirstLoad As Boolean
Public Sub RemoveNode(ByVal TreeNode As Node)
   
  Dim ParentNode As Node
 
  If TreeView1.Nodes(TreeNode.Index).Text <> TreeView1.Nodes(TreeNode.Index).Root.Text Then
   
    If TreeView1.Nodes(TreeNode.Index).Parent.Children = 1 Then
   
      Set ParentNode = TreeView1.Nodes(TreeNode.Index).Parent
      TreeView1.Nodes.Remove TreeNode.Index
      TreeView1.Nodes.Remove ParentNode.Index
   
    Else
   
      TreeView1.Nodes.Remove TreeNode.Index
 
    End If
 
  Else
   
    TreeView1.Nodes.Remove TreeNode.Index
   
  End If
 
End Sub

Private Sub Form_Activate()
 
  If lFirstLoad = True Then
   
    lFirstLoad = False

    Dim nodX As Node
    Set nodX = TreeView1.Nodes.Add(, , "R", "Root")
    Set nodX = TreeView1.Nodes.Add("R", tvwChild, "C1", "Child 1")
    Set nodX = TreeView1.Nodes.Add("R", tvwChild, "C2", "Child 2")
    Set nodX = TreeView1.Nodes.Add("R", tvwChild, "C3", "Child 3")
    Set nodX = TreeView1.Nodes.Add("R", tvwChild, "C4", "Child 4")
    nodX.EnsureVisible
    TreeView1.Style = tvwTreelinesText ' Style 4.
    TreeView1.BorderStyle = vbFixedSingle
   
  End If
 
End Sub

Private Sub Form_Load()
   
  lFirstLoad = True
 
End Sub

Private Sub TreeView1_DblClick()
   
  Call RemoveNode(TreeView1.Nodes(TreeView1.SelectedItem.Index))
 
End Sub
***** End Form1.frm
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vip110598Author Commented:
tward, thank you very much, but
could you answer my 1st question as well?

If you can not, I will have to divide the 2 questions. (50/50)

Thanks.


0
telebasicsCommented:
I belief (i use it myself) that a dblclick on a node always collapse the node, than u can use the _nodecollapse event to prevent it or do something with it.
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

caraf_gCommented:
First question: You can't.

Here's a trick though: In the NodeClick event procedur save the information passed in into some module-level variables. Then in the double-click event procedure do whatever you wanted to do in the node click instead.
0
twardCommented:
What I gave you fires on the DblClick Event and not the NodeClick Event.
0
telebasicsCommented:
tward - the problem with your dblclick is that it uses the selected node not the one that the mouse is on.
0
twardCommented:
Once you dblclick on it, it is the one the mouse is on??
0
telebasicsCommented:
Sorry your right, but again the node enfolds as soon as you dblclick. Without you having to do anything
0
twardCommented:
Once you dblclick on it, it is the one the mouse is on??
0
twardCommented:
Opps, didn't mean to add that again!  I'm not quite sure what vip wants out of question #1...
0
caraf_gCommented:
Another consideration.

You must assume that your users know how to use Windows. They would expect a treeview to do certain things on clicking on a node, and other things when you double click on a node. Inexperienced users are even easier: they can learn.

So, in other words, why not simply code the code on the normal NodeClick event rather than trying to make it work in the double click?
0
vip110598Author Commented:
cararf_g,
I understand what you are saying. I guess it depends
on what you are building. IE.
Windows explorer will fire on a single click, however, the vb6
project explorer will fire (open form or mod) on a dbl. click.

tward, perhaps you can tell me what you do not understand.
I do not know how I can be more clear, :)
but say that I wish to fire the NodeClick event on a dbl. click
only.

Hope this helps.
0
twardCommented:
NodeClick is an Event, simply don't put anything in the event...  Put the code you want in the DblClick Event.

It might be more clear to me if you try to say exactly what you want to do on a DblClick Event.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.