C# treeview node

razza_b
razza_b used Ask the Experts™
on
Anyone know how i can select a child node in a treeview that goes and calls a SP?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Praveen KumarArchitect

Commented:
something like:

private void treeView1_Click(object sender, EventArgs e)
{

switch(treeView1.SelectedNode.Text.ToUpper())
{

case "A":
//Your code

case "B":
//Your code



}



}

Author

Commented:
yes something like that..

or
private void treeView1_Click(object sender, EventArgs e)
{
    if(treeView1.SelectedNode.Text.ToUpper())
    {
        // db conn code
        //call SP with selected node text
    }
}

but everytime i select a different node will this constantly call db sp?
Architect
Commented:
How you want to call your db? You can program anyway you want.

For example, you want call DB only one time, than you can declare a flag variable and run the code using a condition.

bool isFirstTime = true;

private void treeView1_Click(object sender, EventArgs e)
{
    if(treeView1.SelectedNode.Text.ToUpper())
    {
           if(isFirstTime == true)
             {
                  // This is first time, so call your sp and do the things
                 // db conn code
                 //call SP with selected node text
                isFirstTime = false;              }
           else
             {
                 // This is not first time, so any other things.
             }
    }
}

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial