在NX二次开发-UIStyler-Tree(树)的应用(一)中讲了UIStyler-Tree中的添加功能,现在写下编辑和删除功能。
首先是删除功能:
a.删除一个结点:
_ObjectsTree.DeleteNode(node);
将删除本结点和子结点。
b.如果想删除整个树,则用以下代码:
while(_ObjectsTree.RootNode!=null)
{
_ObjectsTree.DeleteNode(_ObjectsTree.RootNode);
}
_ObjectsTree.Redraw(true);
然后是编辑功能:
a.把下面的行注释取消:
//_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)
//{
//}
实现如下的功能:
1、右键添加菜单:
2、左键点击结点,弹出combox编辑框