By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,666 Members | 1,413 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,666 IT Pros & Developers. It's quick & easy.

treeView afterLabelEdit deadly embrace

P: n/a
I created a Windows form and stuck a toolbar on it with one button. I
then added a treeView, docked it to the left of the form and enabled
Label Edit.

Here's the toolbar button click and after label edit event code:

private void toolBar1_ButtonClick(object sender,
System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
if (treeView1.Nodes.Count > 0)
{
if (treeView1.SelectedNode != null)
{
if (treeView1.SelectedNode.IsEditing)
{
MessageBox.Show("You are editing another
node");
return;
}
}
}

TreeNode nextIdea = new TreeNode("", 0, 0);
treeView1.Nodes.Add(nextIdea);
nextIdea.BeginEdit();

}

private void treeView1_AfterLabelEdit(object sender,
System.Windows.Forms.NodeLabelEditEventArgs e)
{
if (e.Label == null)
{
MessageBox.Show("can't be blank (label = null)");
e.CancelEdit = true;
e.Node.BeginEdit();
}
else
if (e.Label.Length == 0)
{
MessageBox.Show("can't be blank (length = 0)");
e.CancelEdit = true;
e.Node.BeginEdit();
}
}

Here's what happens when I click the toolbar button and then click it
again without entering anything in the new node label.

-- get message "can't be blank (label = null)"
(click ok)
-- get message "can't be blank (label = null)"
(click ok)
-- get message "can't be blank (label = null)" and 2nd node appears in
tree view with edit box around it
(click ok)
-- get message "can't be blank (label = null)" and edit box disappears
but 2nd node remains
(click ok)
-- same message and edit box reappears on 2nd node
(click ok)
-- edit box appears around 1st node as well as 2nd
(click ok)
-- edit boxes remain, message window closes

If I click anywhere on or off the form, the message window reappears. If
I close the message window, any further click produce the same behaviour.

If I click the toolbar button again, the whole thing repeats except there
are now 3 nodes in the treeView and so on.

Am I doing something wrong?

All I want to do is add nodes to a list and allow new nodes to be created
while others are still being edited.

Cheers,
..pd.
Nov 13 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.