赞
踩
目录
四、创建和插入Node节点,并对列表添加数据创建和插入Node节点,并对列表添加数据
Blokc UI树列表控件(Tree List)在二次开发中是一个重要的控件,一般被用来加载或记录一些列表类的信息。而树列表相对于其他的控件操作会比较复杂,主要是关于树列表的各种回调函数我们需要熟悉和了解,当学会数据的插入、读取、修改和删除,树列表控件的相关应用就算是掌握了。
在 NxOpen帮助文档BlockStyler命名空间下,有两个类Node和 Tree,这两个类主要是用来操作树列表控件的。
Node类:主要是针对树列表“节点”的操作,比如可以通过Node得到指定节点下的某一列的数据,判断节点是否是选择状态等。NX Open C++ Reference Guide: NXOpen::BlockStyler::Node Class Reference
Tree类:主要是针对各种回调方法和树整体框架的操作,比如通过Tree类可以设置树列表的高度,设置每一列的宽度,创建和删除节点(Node)等操作。NX Open C++ Reference Guide: NXOpen::BlockStyler::Tree Class Reference
NX Open C++ Reference Guide: NXOpen::BlockStyler::Tree Class Reference
- //对树列表插入5列,并设置每一列的标题和宽度
-
- tree_control0->InsertColumn(0, "年级", 200);
- tree_control0->InsertColumn(1, "学号", 200);
- tree_control0->InsertColumn(2, "姓名", 150);
- tree_control0->InsertColumn(3, "性别", 100);
- tree_control0->InsertColumn(4, "成绩", 70);
- //设置指定列不可以排序
- tree_control0->SetColumnSortable(2,false);
-
- //设置指定列是否可见
- tree_control0->SetColumnVisible(3, false);
-
- //得到列的数量
- int num = tree_controlO->NumberOfColumns();
- /*Node* node = tree_controlO->CreateNode("");//创建一个节点
- tree_controlO->InsertNode(node,NULL,NULL,tree_control0->NodelnsertOptionLast);
- node->Expand(Node::ExpandOptionToggle);//设置节点是否展开*/
-
- //创建节点
- Node *node01 = tree_control0->CreateNode("");
- //插入节点
- tree_control0->InsertNode(node01, NULL, NULL, tree_control0->NodeInsertOptionLast);
-
- Node *node02 = tree_control0->CreateNode("");
- tree_control0->InsertNode(node02, NULL, NULL, tree_control0->NodeInsertOptionLast);
- Node *node03 = tree_control0->CreateNode("");
- tree_control0->InsertNode(node03, NULL, NULL, tree_control0->NodeInsertOptionLast);
- Node *node04 = tree_control0->CreateNode("");
- tree_control0->InsertNode(node04, NULL, NULL, tree_control0->NodeInsertOptionLast);
- Node *node05 = tree_control0->CreateNode("");
- tree_control0->InsertNode(node05, NULL, NULL, tree_control0->NodeInsertOptionLast);
- Node *node06 = tree_control0->CreateNode("");
- tree_control0->InsertNode(node06, NULL, NULL, tree_control0->NodeInsertOptionLast);
-
- //设置列的文本
- node01->SetColumnDisplayText(0, "一年级");
- node02->SetColumnDisplayText(0, "二年级");
- node03->SetColumnDisplayText(0, "三年级");
- node04->SetColumnDisplayText(0, "四年级");
- node05->SetColumnDisplayText(0, "五年级");
- node06->SetColumnDisplayText(0, "六年级");
-
-
- Node *node11 = tree_control0->CreateNode("");
- tree_control0->InsertNode(node11, node01, NULL, tree_control0->NodeInsertOptionLast);
- Node *node12 = tree_control0->CreateNode("");
- tree_control0->InsertNode(node12, node02, NULL, tree_control0->NodeInsertOptionLast);
- Node *node13 = tree_control0->CreateNode("");
- tree_control0->InsertNode(node13, node03, NULL, tree_control0->NodeInsertOptionLast);
- Node *node14 = tree_control0->CreateNode("");
- tree_control0->InsertNode(node14, node04, NULL, tree_control0->NodeInsertOptionLast);
- Node *node15 = tree_control0->CreateNode("");
- tree_control0->InsertNode(node15, node05, NULL, tree_control0->NodeInsertOptionLast);
- Node *node16 = tree_control0->CreateNode("");
- tree_control0->InsertNode(node16, node06, NULL, tree_control0->NodeInsertOptionLast);
-
- node11->SetColumnDisplayText(0, "一年级(1)班");
- node11->SetColumnDisplayText(1, "S322070091");
- node11->SetColumnDisplayText(2, "小明");
- node11->SetColumnDisplayText(3, "男");
- node11->SetColumnDisplayText(4, "100");
-
- node12->SetColumnDisplayText(0, "二年级(1)班");
- node12->SetColumnDisplayText(1, "S322070092");
- node12->SetColumnDisplayText(2, "小红");
- node12->SetColumnDisplayText(3, "男");
- node12->SetColumnDisplayText(4, "100");
-
- node13->SetColumnDisplayText(0, "三年级(1)班");
- node13->SetColumnDisplayText(1, "S322070093");
- node13->SetColumnDisplayText(2, "小亮");
- node13->SetColumnDisplayText(3, "男");
- node13->SetColumnDisplayText(4, "100");
-
- node14->SetColumnDisplayText(0, "四年级(1)班");
- node14->SetColumnDisplayText(1, "S322070094");
- node14->SetColumnDisplayText(2, "小峰");
- node14->SetColumnDisplayText(3, "男");
- node14->SetColumnDisplayText(4, "100");
-
- node15->SetColumnDisplayText(0, "五年级(1)班");
- node15->SetColumnDisplayText(1, "S322070095");
- node15->SetColumnDisplayText(2, "小熊");
- node15->SetColumnDisplayText(3, "女");
- node15->SetColumnDisplayText(4, "100");
-
- node16->SetColumnDisplayText(0, "六年级(1)班");
- node16->SetColumnDisplayText(1, "S322070096");
- node16->SetColumnDisplayText(2, "小虎");
- node16->SetColumnDisplayText(3, "男");
- node16->SetColumnDisplayText(4, "100");
- OnSelectCallback//鼠标左键点击回调
- OnStateChangeCallback//状态更改回调
- ToolTipTextCallback//工具提示文本回调
- ColumnSortCallback//列排序回调
- StatelconNameCallback//图标名称回调
- OnBeginLabelEditCallback//编辑回调
- OnEndLabelEditCallback//结束编辑回调
- OnEditOptionSelectedCallback//选择回调
- AskEditControlCallback//编辑控件回调
- OnMenuCallback//右键菜单的回调
- OnMenuSelectionCallback//菜单选择回调
- lsDragAllowedCallback//是否允许拖动回调
- OnDropMenuCallback//在下拉菜单回调
- //第一个参数树列表ID,第二个参数节点ID,第三个参数选中列的ID,第四个参数,当前是选中状态还是取消状态
- void NXOpen_create_treelist::OnSelectCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int columnID, bool selected)
- {
- if (tree == tree_control0)//判断树列表
- {
- if (selected)
- {
- //获得选中列对应行的数据
- NXString strValue = node->GetColumnDisplayText(columnID);
- uc1601((char*)strValue.GetLocaleText(), 1);
- }
- }
- }
- enum MenuID
- {
- DeleteNote, helpbutton
- };
-
-
-
- //右键弹出回调
- void NXOpen_create_treelist::OnMenuCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int columnID )
- {
- BlockStyler::TreeListMenu *menu = tree->CreateMenu();//创建菜单
- if (node != NULL)
- {
- menu->AddMenuItem(MenuID(DeleteNote), "删除");
- menu->AddMenuItem(MenuID(helpbutton), "帮助");
- }
- tree->SetMenu(menu); //设置菜单
- delete menu;
- }
- //右键响应选中的命令
- void NXOpen_create_treelist::OnMenuSelectionCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int menuItemID)
- {
- if ((MenuID)menuItemID == DeleteNote)
- {
- tree->DeleteNode(node); // 执行删除操作
- }
- else if ((MenuID)menuItemID == helpbutton)
- {
- uc1601("帮助", 1);
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。