NodeLabelEditEventArgs Class
Provides data for the BeforeLabelEdit and AfterLabelEdit events.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
The NodeLabelEditEventArgs type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | NodeLabelEditEventArgs(TreeNode) | Initializes a new instance of the NodeLabelEditEventArgs class for the specified TreeNode. |
![]() | NodeLabelEditEventArgs(TreeNode, String) | Initializes a new instance of the NodeLabelEditEventArgs class for the specified TreeNode and the specified text with which to update the tree node label. |
| Name | Description | |
|---|---|---|
![]() | CancelEdit | Gets or sets a value indicating whether the edit has been canceled. |
![]() | Label | Gets the new text to associate with the tree node. |
![]() | Node | Gets the tree node containing the text to edit. |
| Name | Description | |
|---|---|---|
![]() | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
The AfterLabelEdit event occurs when the user finishes editing the text for a tree node. The BeforeLabelEdit event occurs when the user begins editing the text for a tree node. A NodeLabelEditEventArgs object specifies the new text to associate with the tree node, the tree node that contains the label to edit, and whether the edit operation has been canceled.
For more information about handling events, see Consuming Events.
The following example allows the user to edit nonroot tree nodes by using a ContextMenu. When the user right clicks the mouse, the TreeNode at that position is determined and stored in a variable named mySelectedNode. If a nonroot tree node was selected, it is put into an editable state, allowing the user to edit the node label. After the user stops editing the tree node label, the new label text is evaluated and saved. For this example, several characters are considered not valid in the label text. If one of the invalid characters is in the label string, or the string is empty, the user is notified of the error and the label is returned to its previous text.
/* Get the tree node under the mouse pointer and save it in the mySelectedNode variable. */ private: void treeView1_MouseDown( Object^ /*sender*/, System::Windows::Forms::MouseEventArgs^ e ) { mySelectedNode = treeView1->GetNodeAt( e->X, e->Y ); } void menuItem1_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ ) { if ( mySelectedNode != nullptr && mySelectedNode->Parent != nullptr ) { treeView1->SelectedNode = mySelectedNode; treeView1->LabelEdit = true; if ( !mySelectedNode->IsEditing ) { mySelectedNode->BeginEdit(); } } else { MessageBox::Show( String::Concat( "No tree node selected or selected node is a root node.\n", "Editing of root nodes is not allowed." ), "Invalid selection" ); } } void treeView1_AfterLabelEdit( Object^ /*sender*/, System::Windows::Forms::NodeLabelEditEventArgs^ e ) { if ( e->Label != nullptr ) { if ( e->Label->Length > 0 ) { array<Char>^ temp0 = {'@','.',',','!'}; if ( e->Label->IndexOfAny( temp0 ) == -1 ) { // Stop editing without canceling the label change. e->Node->EndEdit( false ); } else { /* Cancel the label edit action, inform the user, and place the node in edit mode again. */ e->CancelEdit = true; MessageBox::Show( String::Concat( "Invalid tree node label.\n", "The invalid characters are: '@','.', ',', '!'" ), "Node Label Edit" ); e->Node->BeginEdit(); } } else { /* Cancel the label edit action, inform the user, and place the node in edit mode again. */ e->CancelEdit = true; MessageBox::Show( "Invalid tree node label.\nThe label cannot be blank", "Node Label Edit" ); e->Node->BeginEdit(); } } }
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
