In NX secondary development-UIStyler-Tree (tree) application (1), I talked about the addition function in UIStyler-Tree, and now write down the edit and delete functions.
The first is the delete function:
a. Delete a node:
_ObjectsTree.DeleteNode(node);
The current node and child nodes will be deleted.
b. If you want to delete the entire tree, use the following code:
while(_ObjectsTree.RootNode!=null)
{
_ObjectsTree.DeleteNode(_ObjectsTree.RootNode);
}
_ObjectsTree.Redraw(true);
Then there is the editing function:
a. Uncomment the following line:
//_ObjectsTree.SetOnEndLabelEditHandler(new NXOpen.BlockStyler.Tree.OnEndLabelEditCallback(OnEndLabelEditCallback));
_ObjectsTree.SetOnEditOptionSelectedHandler(new NXOpen.BlockStyler.Tree.OnEditOptionSelectedCallback(OnEditOptionSelectedCallback));
_ObjectsTree.SetAskEditControlHandler(new NXOpen.BlockStyler.Tree.AskEditControlCallback(AskEditControlCallback));
_ObjectsTree.SetOnMenuHandler(new NXOpen.BlockStyler.Tree.OnMenuCallback(OnMenuCallback)); ;
_ObjectsTree.SetOnMenuSelectionHandler(new NXOpen.BlockStyler.Tree.OnMenuSelectionCallback(OnMenuSelectionCallback)); ;
//_ObjectsTree.SetIsDropAllowedHandler(new NXOpen.BlockStyler.Tree.IsDropAllowedCallback(IsDropAllowedCallback));;
//_ObjectsTree.SetIsDragAllowedHandler(new NXOpen.BlockStyler.Tree.IsDragAllowedCallback(IsDragAllowedCallback));;
public Tree.EditControlOption OnEditOptionSelectedCallback(NXOpen.BlockStyler.Tree tree, NXOpen.BlockStyler.Node node, int columnID, int selectedOptionID, string selectedOptionText, Tree.ControlType type)
{
if(tree==_ObjectsTree)
{
//type = Tree.ControlType.ComboBox;
return Tree.EditControlOption.Accept;
}
else
{
return Tree.EditControlOption.Reject;
}
}
public Tree.ControlType AskEditControlCallback(NXOpen.BlockStyler.Tree tree, NXOpen.BlockStyler.Node node, int columnID)
{
return Tree.ControlType.ComboBox;
}
public void OnMenuCallback(NXOpen.BlockStyler.Tree tree, NXOpen.BlockStyler.Node node, int columnID)
{
TreeListMenu treeListMenu = tree.CreateMenu();
treeListMenu.AddMenuItem(1, "删除");
treeListMenu.AddMenuItem(2, "编辑");
tree.SetMenu(treeListMenu);
}
public void OnMenuSelectionCallback(NXOpen.BlockStyler.Tree tree, NXOpen.BlockStyler.Node node, int menuItemID)
{
if (menuItemID == 1)
{
_ObjectsTree.DeleteNode(node);
NXUtilityTools.AllObjectsUnhightlight();
}
if(menuItemID==2)
{
string[] stringArray = new string[2] {"1111","2222"};
_ObjectsTree.SetEditOptions(stringArray,1);
}
}
//public Node.DropType IsDropAllowedCallback(NXOpen.BlockStyler.Tree tree, NXOpen.BlockStyler.Node node, int columnID, NXOpen.BlockStyler.Node targetNode, int targetColumnID)
//{
//}
Realize the following functions:
1. Right click to add menu:
2. Left click on the node to pop up the combox edit box