TreeView AfterLabelEdit - no work

B

bob

Hello,

the nodes in my tree view show a name and then a suffix. I want to be
able to edit the name using 'label edit' but I want the suffix to be
removed and then added after the edit. I try this with the events
AfterLabelEdit and BeforeLabelEdit but they don't do anything. The
following bit of code just has a tree view with some nodes and has
BeforeLabelEdit set to change the node text to 'editing':

private void treeView1_BeforeLabelEdit(object sender,
System.Windows.Forms.NodeLabelEditEventArgs e)
{
e.Node.Text = "Editing";
}


But it doesn't do anything.

Any one have any ideas?

sorry about the long post

Thanks,

Bob


using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace TreeViewTest
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TreeView treeView1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.treeView1 = new System.Windows.Forms.TreeView();
this.SuspendLayout();
//
// treeView1
//
this.treeView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.treeView1.ImageIndex = -1;
this.treeView1.LabelEdit = true;
this.treeView1.Location = new System.Drawing.Point(0, 0);
this.treeView1.Name = "treeView1";
this.treeView1.Nodes.AddRange(new System.Windows.Forms.TreeNode[] {
new System.Windows.Forms.TreeNode("Node0", new
System.Windows.Forms.TreeNode[] {
new
System.Windows.Forms.TreeNode("Node1", new
System.Windows.Forms.TreeNode[] {
new
System.Windows.Forms.TreeNode("Node4", new
System.Windows.Forms.TreeNode[] {

new System.Windows.Forms.TreeNode("Node5"),

new System.Windows.Forms.TreeNode("Node6")})}),
new
System.Windows.Forms.TreeNode("Node2", new
System.Windows.Forms.TreeNode[] {
new
System.Windows.Forms.TreeNode("Node3")})})});
this.treeView1.SelectedImageIndex = -1;
this.treeView1.Size = new System.Drawing.Size(292, 266);
this.treeView1.TabIndex = 1;
this.treeView1.AfterLabelEdit += new
System.Windows.Forms.NodeLabelEditEventHandler(this.treeView1_AfterLabelEdit);
this.treeView1.BeforeLabelEdit += new
System.Windows.Forms.NodeLabelEditEventHandler(this.treeView1_BeforeLabelEdit);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.treeView1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}


private void treeView1_BeforeLabelEdit(object sender,
System.Windows.Forms.NodeLabelEditEventArgs e)
{
e.Node.Text = "Editing";
}

private void treeView1_AfterLabelEdit(object sender,
System.Windows.Forms.NodeLabelEditEventArgs e)
{
e.Node.Text = "Edited";
}
}
}
 
S

Shakir Hussain

Do this in AfterLabel Edit event

private void treeView1_AfterLabelEdit(object sender,
System.Windows.Forms.NodeLabelEditEventArgs e)
{
string text = e.Label;
e.CancelEdit = true;
e.Node.Text = "Edited: " + text;
}



--
Shak
(Houston)




bob said:
Hello,

the nodes in my tree view show a name and then a suffix. I want to be
able to edit the name using 'label edit' but I want the suffix to be
removed and then added after the edit. I try this with the events
AfterLabelEdit and BeforeLabelEdit but they don't do anything. The
following bit of code just has a tree view with some nodes and has
BeforeLabelEdit set to change the node text to 'editing':

private void treeView1_BeforeLabelEdit(object sender,
System.Windows.Forms.NodeLabelEditEventArgs e)
{
e.Node.Text = "Editing";
}


But it doesn't do anything.

Any one have any ideas?

sorry about the long post

Thanks,

Bob


using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace TreeViewTest
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TreeView treeView1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.treeView1 = new System.Windows.Forms.TreeView();
this.SuspendLayout();
//
// treeView1
//
this.treeView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.treeView1.ImageIndex = -1;
this.treeView1.LabelEdit = true;
this.treeView1.Location = new System.Drawing.Point(0, 0);
this.treeView1.Name = "treeView1";
this.treeView1.Nodes.AddRange(new System.Windows.Forms.TreeNode[] {
new System.Windows.Forms.TreeNode("Node0", new
System.Windows.Forms.TreeNode[] {
new
System.Windows.Forms.TreeNode("Node1", new
System.Windows.Forms.TreeNode[] {
new
System.Windows.Forms.TreeNode("Node4", new
System.Windows.Forms.TreeNode[] {

new System.Windows.Forms.TreeNode("Node5"),

new System.Windows.Forms.TreeNode("Node6")})}),
new
System.Windows.Forms.TreeNode("Node2", new
System.Windows.Forms.TreeNode[] {
new
System.Windows.Forms.TreeNode("Node3")})})});
this.treeView1.SelectedImageIndex = -1;
this.treeView1.Size = new System.Drawing.Size(292, 266);
this.treeView1.TabIndex = 1;
this.treeView1.AfterLabelEdit += new
System.Windows.Forms.NodeLabelEditEventHandler(this.treeView1_AfterLabelEdit
);
this.treeView1.BeforeLabelEdit += new
System.Windows.Forms.NodeLabelEditEventHandler(this.treeView1_BeforeLabelEdi
t);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.treeView1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}


private void treeView1_BeforeLabelEdit(object sender,
System.Windows.Forms.NodeLabelEditEventArgs e)
{
e.Node.Text = "Editing";
}

private void treeView1_AfterLabelEdit(object sender,
System.Windows.Forms.NodeLabelEditEventArgs e)
{
e.Node.Text = "Edited";
}
}
}
 
B

bob

Thanks for your help Shak, your tip fixes the AfterLabelEdit event.

But what about the BeforeLabelEdit event, I still don't seem to be
able to change the text at the start of the edit operation.

Any ideas?


Shakir Hussain said:
Do this in AfterLabel Edit event

private void treeView1_AfterLabelEdit(object sender,
System.Windows.Forms.NodeLabelEditEventArgs e)
{
string text = e.Label;
e.CancelEdit = true;
e.Node.Text = "Edited: " + text;
}



--
Shak
(Houston)




bob said:
Hello,

the nodes in my tree view show a name and then a suffix. I want to be
able to edit the name using 'label edit' but I want the suffix to be
removed and then added after the edit. I try this with the events
AfterLabelEdit and BeforeLabelEdit but they don't do anything. The
following bit of code just has a tree view with some nodes and has
BeforeLabelEdit set to change the node text to 'editing':

private void treeView1_BeforeLabelEdit(object sender,
System.Windows.Forms.NodeLabelEditEventArgs e)
{
e.Node.Text = "Editing";
}


But it doesn't do anything.

Any one have any ideas?

sorry about the long post

Thanks,

Bob


using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace TreeViewTest
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TreeView treeView1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
} base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.treeView1 = new System.Windows.Forms.TreeView();
this.SuspendLayout();
//
// treeView1
//
this.treeView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.treeView1.ImageIndex = -1;
this.treeView1.LabelEdit = true;
this.treeView1.Location = new System.Drawing.Point(0, 0);
this.treeView1.Name = "treeView1";
this.treeView1.Nodes.AddRange(new System.Windows.Forms.TreeNode[] {
new System.Windows.Forms.TreeNode("Node0", new
System.Windows.Forms.TreeNode[] {
new
System.Windows.Forms.TreeNode("Node1", new
System.Windows.Forms.TreeNode[] {
new
System.Windows.Forms.TreeNode("Node4", new
System.Windows.Forms.TreeNode[] {

new System.Windows.Forms.TreeNode("Node5"),

new System.Windows.Forms.TreeNode("Node6")})}),
new
System.Windows.Forms.TreeNode("Node2", new
System.Windows.Forms.TreeNode[] {
new
System.Windows.Forms.TreeNode("Node3")})})});
this.treeView1.SelectedImageIndex = -1;
this.treeView1.Size = new System.Drawing.Size(292, 266);
this.treeView1.TabIndex = 1;
this.treeView1.AfterLabelEdit += new
System.Windows.Forms.NodeLabelEditEventHandler(this.treeView1_AfterLabelEdit
);
this.treeView1.BeforeLabelEdit += new
System.Windows.Forms.NodeLabelEditEventHandler(this.treeView1_BeforeLabelEdi
t);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.treeView1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}


private void treeView1_BeforeLabelEdit(object sender,
System.Windows.Forms.NodeLabelEditEventArgs e)
{
e.Node.Text = "Editing";
}

private void treeView1_AfterLabelEdit(object sender,
System.Windows.Forms.NodeLabelEditEventArgs e)
{
e.Node.Text = "Edited";
}
}
}
 
M

Michael C

As Shakir once told me, try the OnClick() event.

Thanks,
Michael C.

bob said:
Thanks for your help Shak, your tip fixes the AfterLabelEdit event.

But what about the BeforeLabelEdit event, I still don't seem to be
able to change the text at the start of the edit operation.

Any ideas?


"Shakir Hussain" <[email protected]> wrote in message
Do this in AfterLabel Edit event

private void treeView1_AfterLabelEdit(object sender,
System.Windows.Forms.NodeLabelEditEventArgs e)
{
string text = e.Label;
e.CancelEdit = true;
e.Node.Text = "Edited: " + text;
}



--
Shak
(Houston)




bob said:
Hello,

the nodes in my tree view show a name and then a suffix. I want to be
able to edit the name using 'label edit' but I want the suffix to be
removed and then added after the edit. I try this with the events
AfterLabelEdit and BeforeLabelEdit but they don't do anything. The
following bit of code just has a tree view with some nodes and has
BeforeLabelEdit set to change the node text to 'editing':

private void treeView1_BeforeLabelEdit(object sender,
System.Windows.Forms.NodeLabelEditEventArgs e)
{
e.Node.Text = "Editing";
}


But it doesn't do anything.

Any one have any ideas?

sorry about the long post

Thanks,

Bob


using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace TreeViewTest
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TreeView treeView1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
} base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.treeView1 = new System.Windows.Forms.TreeView();
this.SuspendLayout();
//
// treeView1
//
this.treeView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.treeView1.ImageIndex = -1;
this.treeView1.LabelEdit = true;
this.treeView1.Location = new System.Drawing.Point(0, 0);
this.treeView1.Name = "treeView1";
this.treeView1.Nodes.AddRange(new System.Windows.Forms.TreeNode[] {
new System.Windows.Forms.TreeNode("Node0", new
System.Windows.Forms.TreeNode[] {
new
System.Windows.Forms.TreeNode("Node1", new
System.Windows.Forms.TreeNode[] {
new
System.Windows.Forms.TreeNode("Node4", new
System.Windows.Forms.TreeNode[] {

new System.Windows.Forms.TreeNode("Node5"),

new System.Windows.Forms.TreeNode("Node6")})}),
new
System.Windows.Forms.TreeNode("Node2", new
System.Windows.Forms.TreeNode[] {
new
System.Windows.Forms.TreeNode("Node3")})})});
this.treeView1.SelectedImageIndex = -1;
this.treeView1.Size = new System.Drawing.Size(292, 266);
this.treeView1.TabIndex = 1;
this.treeView1.AfterLabelEdit += new
System.Windows.Forms.NodeLabelEditEventHandler(this.treeView1_AfterLabelEdit
);
this.treeView1.BeforeLabelEdit += new
System.Windows.Forms.NodeLabelEditEventHandler(this.treeView1_BeforeLabelEdi
t);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.treeView1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}


private void treeView1_BeforeLabelEdit(object sender,
System.Windows.Forms.NodeLabelEditEventArgs e)
{
e.Node.Text = "Editing";
}

private void treeView1_AfterLabelEdit(object sender,
System.Windows.Forms.NodeLabelEditEventArgs e)
{
e.Node.Text = "Edited";
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top