Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Treeview issue

Status
Not open for further replies.

Ruffnekk

Programmer
Aug 2, 2005
249
DE
Hi all,

I have an MDI parent form which has a Treeview control directly on it, docked left. The remaining space will have MDI child forms.

When I (at runtime) add a node to the Treeview, I want the user to be able to edit the textlabel of the node immediately without interaction. The code I have so far:

Code:
private void SelectAndEditNode(string id)
{
    TreeNode[] temp = tvwProjects.Nodes.Find(id, true);

    if (temp != null && temp.Length > 0)
    {
        tvwProjects.SelectedNode = temp[0];
        tvwProjects.SelectedNode.EnsureVisible();
        tvwProjects.SelectedNode.BeginEdit();
    }
}

As you can see, I search the newest node by it's Key, make it the selected node, ensure it's visible and begin editing the label. So far so good, this works perfectly.

BUT, when I start typing to assign a new name to the node, it accepts one character and then gives the focus to the last active MDI child.

If there are no MDI children then it works fine.

I've tried calling .Focus() on the treeview before .BeginEdit() but no luck.

Does anyone have an idea why this happens? Or better yet, how to make it work correctly?

Regards, Ruffnekk
---
Is it true that cannibals don't eat clowns because they taste funny?
 
have you tried stepping throught he code using F-11 in visual studio? there might be some other code firing.
 
Yes I tried debugging it but I can't see any event being fired after I start editing the treenode label's text.

Regards, Ruffnekk
---
Is it true that cannibals don't eat clowns because they taste funny?
 
theres still events that could be firing, form events that you dont have code in.

I'm gonna guess you are firing your above method from one of your MDI children, am i right?

Try putting debug messages in a bunch of events that you havent used, my first suspect would be the Activate, Deactivate events of the mdi child if you arent using those. Something such as a mousemove could be causing the mdi child to retake focus. Or maybe the keypreview of either the parent form or one of the MDI children is being triggered as soon as you start typing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top