Hi all i have a problem in C# window application...........
Well i am making a application in which i am making treeview control, in which i have some nodes, and when i click on particular node, so related form is displaying in side panel............
But the problem is that,After debugging when my application is start so first node of that treeview looks automatically selected, and corresponding form is displaying in side panel, which i dont want, i want when i click on that node, then only corresponding form will be open in side panel....
In case of below nodes of treeview it is working fine, this problem only occurs in case of first node of treeview control................
Can anyone help me in this..............

Hello.
Interesting question ..
I couldn't find any property or method for this case, but here's some workaround. You can process the BeforeSelect event and cancel it if the selection made e.g. not using mouse:

private void treeView1_BeforeSelect(object sender, TreeViewCancelEventArgs e)
        {
            if (e.Action != TreeViewAction.ByMouse)
            {
                e.Cancel = true;
            }
        }

Hello.
Interesting question ..
I couldn't find any property or method for this case, but here's some workaround. You can process the BeforeSelect event and cancel it if the selection made e.g. not using mouse:

private void treeView1_BeforeSelect(object sender, TreeViewCancelEventArgs e)
        {
            if (e.Action != TreeViewAction.ByMouse)
            {
                e.Cancel = true;
            }
        }

Well thanks for your reply Antenka...........
Actually some times this error occur and some time not, even i dont know why.........
Can you tell me why this is happen.........?

Hm .. hard to say ..

The selection appears as soon as your treeView get the focus. You can also play around TabIntex Property. If it's set to 0 (so your treView will be the first selected control on your form) then the node in it will be selected.

The other way to go would be - changing TabIntex so that treeView get's the input focus not in the first place.

But if I were you - I would choose the event-handling way .. in my opinion it gives more tangible control over treeView (but that's probably the question of comfort for developer :) ) So - you decide.

Hm .. hard to say ..

But if I were you - I would choose the event-handling way .. in my opinion it gives more tangible control over treeView (but that's probably the question of comfort for developer :) ) So - you decide.

No Actually you are right........
I just want to know the other ways also, thats why i was asking you............
Anyways Thanks for helping me Antenka............:)

You're welcome .. please, mark this thread as Solved if your question is settled :)

Hi all i have a problem in C# window application...........
Well i am making a application in which i am making treeview control, in which i have some nodes, and when i click on particular node, so related form is displaying in side panel............
But the problem is that,After debugging when my application is start so first node of that treeview looks automatically selected, and corresponding form is displaying in side panel, which i dont want, i want when i click on that node, then only corresponding form will be open in side panel....
In case of below nodes of treeview it is working fine, this problem only occurs in case of first node of treeview control................
Can anyone help me in this..............

Well probably this is because of you set taborder of treeview is zero, you just change that, i am sure it will help you

It looks like you already have been given an answer to your question :)

You can also see if the node is the top-most node by looking at the node collection:

namespace daniweb
{
  public partial class frmTree2 : Form
  {
    public frmTree2()
    {
      InitializeComponent();
    }

    private void frmTree2_Load(object sender, EventArgs e)
    {
      treeView1.Nodes.Add("First Node");
      treeView1.Nodes.Add("Second Node");
      treeView1.Nodes.Add("Third Node");
    }

    private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
    {
      if ((treeView1.Nodes.Count == 0) || (e.Node == treeView1.Nodes[0]))
      {
        Console.WriteLine("Hiding the panels...");
      }
      else
      {
        Console.WriteLine("Showing the panels for {0}...", e.Node.Text);
      }
    }
  }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.