Windows Develop Bookmark and Share   
 index > Windows Forms Designer > More TreeView Issues - OnMouse and AfterLabelEdit Problem
 

More TreeView Issues - OnMouse and AfterLabelEdit Problem

I have a treeview with a single parent node (title) and 5 child nodes (name,address,city,state,zip)

I want the user to edit the 5 children, no problem.

However, after they edit let's say child node 0 I want the next node to be selected and ready to edit:

Now look at this code:

private void tvCust_MouseDown(object sender, MouseEventArgs e)

{

TreeViewHitTestInfo hti = tvCust.HitTest(e.X, e.Y);

if (hti.Node != null)

{

if (hti.Node.Parent != null)

{

if (hti.Node.Parent.Text == "New Billing Or Site Address")

{

//hti.Node.BeginEdit();

}

else

tvCust.SelectedNode = hti.Node;

}

}

}

private void tvCust_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)

{

if (e.Node.Parent.Text == "New Billing Or Site Address")

{

switch (e.Node.Index)

{

case 0:

e.Node.BackColor = System.Drawing.Color.White;

tvCust.Nodes[0].Nodes[1].BeginEdit();

break;

default:

break;

}

}

}

The FIRST time I click in node 0, it calls the mousedown fine, THEN it calls afterlabeledit, followed by another mousedown. This only happens the first time. what the heck am I missing? TREEVIEWS ARGH.

melegant  Tuesday, October 09, 2007 2:34 AM

Hi, melegant,

Based on my understanding, you want to enable the user to edit the 5 ChildNodes and move to next when the node is edited, don't you?

I think there are some logic problems in your codes and I wrote another one for you.

In fact, you don't need to use MouseDown to test the Labels, you can just use BeforeLabelEdit to do that.

For example

Code Block

private void tvCust_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)

{

if (e.Node.Parent!=null && e.Node.Parent.Text == "New Billing Or Site Address") //If it is not the title node

{

if(e.Node.NextNode!=null) //If it is not the last node

{

e.Node.BackColor=System.Drawing.Color.White;

e.Node.NextNode.BeginEdit();

}

}

}

private void tvCust_BeforeLabelEdit(object sender, NodeLabelEditEventArgs e)

{

if (e.Node.Parent == null) //If it is the title node.

{

e.CancelEdit = true;

}

}

http://msdn2.microsoft.com/en-us/library/system.windows.forms.treeview.afterlabeledit.aspx

http://msdn2.microsoft.com/en-us/library/system.windows.forms.listview.beforelabeledit.aspx

Hope this helps,

Regards

Yu Guo â€?MSFT  Thursday, October 11, 2007 9:34 AM

Hi, melegant,

Based on my understanding, you want to enable the user to edit the 5 ChildNodes and move to next when the node is edited, don't you?

I think there are some logic problems in your codes and I wrote another one for you.

In fact, you don't need to use MouseDown to test the Labels, you can just use BeforeLabelEdit to do that.

For example

Code Block

private void tvCust_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)

{

if (e.Node.Parent!=null && e.Node.Parent.Text == "New Billing Or Site Address") //If it is not the title node

{

if(e.Node.NextNode!=null) //If it is not the last node

{

e.Node.BackColor=System.Drawing.Color.White;

e.Node.NextNode.BeginEdit();

}

}

}

private void tvCust_BeforeLabelEdit(object sender, NodeLabelEditEventArgs e)

{

if (e.Node.Parent == null) //If it is the title node.

{

e.CancelEdit = true;

}

}

http://msdn2.microsoft.com/en-us/library/system.windows.forms.treeview.afterlabeledit.aspx

http://msdn2.microsoft.com/en-us/library/system.windows.forms.listview.beforelabeledit.aspx

Hope this helps,

Regards

Yu Guo â€?MSFT  Thursday, October 11, 2007 9:34 AM
Thanks again...=D. Sometimes you get so focused on doing it a certain way you forget to think...

melegant  Thursday, October 11, 2007 10:54 AM

You can use google to search for other answers

Custom Search

More Threads

• Drow combobox-like control list area over all controls
• How to modify TaskBar Menu of a Program
• Resizing user control
• designer problem: inheriting from TextBox
• ContolTab question
• Custom user controls will not show up automatically on toolbox
• Move non-container user control
• Usercontrol customproperties
• WSOD: Could not load file or assembly for assemblies in project references
• Custom Report field in Windows Application