Treeview - click on Node and open specific screen

Asked

Viewed 494 times

1

I have a TreeView, with some settings items:

inserir a descrição da imagem aqui

I would like to double click on one node it opens a specific form, the event of double-clicking and open the form, is OK, the problem is how I distinguish a node of the other?

Example, by double-clicking on Users he opens the screen Users, by double clicking on Permissions he opens the permissions screen.

Event DoubleClick:

this.treeView1.NodeMouseDoubleClick += 
new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.TreeView1_doubleClick);

Method I’m using to generate the doubleclick:

private void TreeView1_doubleClick(Object sender, TreeNodeMouseClickEventArgs e)// clicar em usuarios     
{
     Manutencao_usuarios clickmu = new Manutencao_usuarios();
     clickmu.ShowDialog();
}

1 answer

1


You can do this at the event NodeMouseDoubleClick of TreeView:

private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
{
    string node = e.Node.Text;
    switch (node)
    {
        case "Servidores e Diretórios":
            // Abrir o formulário Servidores e Diretórios
            break;
        case "Usuários":
            // Abrir o formulário Usuários
            break;

        // Restante do código...

        default:
            // Fazer algo se nenhuma das opções acima for clicada
            break;
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.