c# .net treeview... double click expanding vs executing further processing

Hi Experts!!

I have a treeview in a winforms c#.net app that I want to on double click expand to the child nodes if they exist, if they don't, it considers it the lowest level and calls a process to generate a report.

Right now I have it calling the process successfully but if it is not the lowest level node and they double click, it will call the process as well and that's not good.  So I need to add logic to identify if the selected node has children and if so, just expand to the next level. If not, call the further processing.

I'm not sure how to do that. Can you help me?
babybirdAsked:
Who is Participating?
 
anarki_jimbelConnect With a Mentor Commented:
DoubleClick event does NOT contain TreeEventArgs argument ...

        private void treeView1_DoubleClick(object sender, EventArgs e)
        {

            TreeView tv = sender as TreeView;
            TreeNode selected = tv.SelectedNode;
            if (selected == null)
                return;

            if (selected.Nodes.Count == 0)
            {
                runProcess();
            }
            else
            {
                selected.Expand();
            }
        }
0
 
NetworkArchitekCommented:
So in your double click event, assuming the TreeEventArgs argument is called e, then do

if(e.Node.Nodes.Count == 0)
           runProcess();
0
All Courses

From novice to tech pro — start learning today.