当前位置: 首页 > article >正文

Nodes 节点

Goto Tree List 树列表

Nodes 节点

Tree List 节点是组织成树状层次结构的数据行。

在这里插入图片描述

Add New Nodes 添加新节点

如果 Tree List 具有数据源,则会自动生成节点(TreeListNode 类对象)。要在未绑定模式下添加节点,请调用“树列表设计器”对话框并切换到其“节点”选项卡。

在这里插入图片描述

Add New Nodes in Code 在代码中添加新节点

使用 TreeList.AppendNode 方法将新节点添加到 Tree List。

using DevExpress.XtraTreeList;
using DevExpress.XtraTreeList.Nodes;

TreeListNode parentForRootNodes = null;
// Create a root node.
TreeListNode rootNode = tl.AppendNode(new object[] { "Alfreds Futterkiste", "Germany, Obere Str. 57", "030-0074321" }, parentForRootNodes);
// Create the root node's child node.
tl.AppendNode(new object[] { "Suyama, Michael", "Obere Str. 55", "030-0074263" }, rootNode);

使用以下参数指定新节点的单元格值及其在树层次结构中的位置:

  • nodeData - 用于初始化新节点的单元格值的值数组或 DataRow 对象。数组的值类型必须与数据源中的列类型匹配;否则,将引发异常。

  • parentNode - 一个 TreeListNode 对象,用于指定新节点的父节点。此值将分配给 ParentNode 属性。要附加根节点,请使用 null(VB 中的 Nothing)。

    如果您在 nodeData 参数的相应字段中指定了父节点,则 parentNode 参数应指定相同的节点。

  • parentNodeId - 一个整数值,该值通过其 Id 属性值指定新节点的父节点。

使用以下参数指定新节点中显示的图像。要指定图像,请使用 SelectImageList 集合中的图像索引。

  • imageIndex - 节点未聚焦时显示的图像。此值分配给 ImageIndex 属性。
  • selectImageIndex - 聚焦节点时显示的图像。此值分配给 SelectImageIndex 属性。

使用 checkState 参数指定是否选中节点。如果启用了 AllowRecursiveNodeChecking 选项,则该方法将更新父节点和子节点。

使用 childrenCheckBoxStyle 参数可指定新节点的子节点是显示复选框、单选按钮,还是两者都不显示。此值将分配给 ChildrenCheckBoxStyle 属性。

使用 tag 参数将自定义数据与新节点关联。此值分配给 Tag 属性。

Access Nodes 访问节点

您可以使用 TreeList.Nodes 属性访问控件根级别的节点。

//get the second node by its index
TreeListNode node = treeList1.Nodes[1];
//get all nodes that contain the "R&D" caption
var nodes = treeList1.Nodes.Where(n => n.GetDisplayText("Department").Contains("R&D"));

每个节点都有一个 TreeList.Nodes 存储子节点的集合。您可以使用节点迭代器或以下 API 来检索这些集合中的节点:

  • TreeList.FocusedNode - 获取或设置聚焦节点。
  • TreeList.FindNodeByFieldValue - 按字段值返回节点。
TreeListNode node = treeList1.FindNodeByFieldValue("Employee Name", "Kate Mossheart");
  • TreeList.FindNodeByKeyID - 按节点的键字段值返回节点。
  • TreeList.FindNodeByID - 返回由其标识符指定的节点。

Node Icons 节点图标

节点单元格可以包含一个图标。本节介绍可用于在单元格中显示图像的各种方法。

Select and State Icons Select 和 State 图标

您可以将 select 和 state 图标应用于节点。

在这里插入图片描述
如果 TreeListOptionsView.RowImagesShowMode 属性设置为 InCell,则图标将显示在节点单元格内。

在这里插入图片描述
有关更多信息,请参阅以下帮助主题:节点映像。

Conditional Formatting 条件格式

当您有一组显示不同值或值范围的图标时,请使用此方法。在下图中,指示市场份额增长的图标显示在单元格值旁边。

在这里插入图片描述
有关更多信息,请参阅以下帮助主题:条件格式。

Combo Box with Images 带图像的组合框

您可以使用此方法为单元格值提供图像,也可以将文本条目完全替换为这些图像。下面的代码将复选框替换为包含布尔值的列中的图标。

在这里插入图片描述

using DevExpress.XtraEditors.Repository;

RepositoryItemImageComboBox repositoryItemDescriptionComboBox;
repositoryItemDescriptionComboBox = new RepositoryItemImageComboBox();
repositoryItemDescriptionComboBox.AutoHeight = false;
repositoryItemDescriptionComboBox.GlyphAlignment = DevExpress.Utils.HorzAlignment.Center;
repositoryItemDescriptionComboBox.SmallImages = svgImageCollection;
repositoryItemDescriptionComboBox.Items.Add("", true, 3);

treeList1.RepositoryItems.Add(repositoryItemDescriptionComboBox);
descriptionColumn.ColumnEdit = repositoryItemDescriptionComboBox;

Context Icons in Text Box 文本框中的上下文图标

RepositoryItemTextEdit.ContextImageOptions 指定分配给文本框的栅格或矢量图标。您可以在使用此存储库项目的所有单元格中显示相同的图标。要在单个单元格中显示不同的图标,请创建多个 RepositoryItemTextEdit 对象并处理 TreeList.CustomNodeCellEdit 事件以将这些存储库项目分配给单元格。在下面的示例中,将带有上下文图像的文本框分配给包含“Arthur Miller”的单元格。

在这里插入图片描述

using DevExpress.XtraEditors.Repository;

RepositoryItemTextEdit repositoryItemTextEdit2;
repositoryItemTextEdit2 = new RepositoryItemTextEdit();
repositoryItemTextEdit2.ContextImageOptions.SvgImage = svgImageCollection[0];
treeList1.RepositoryItems.Add(repositoryItemTextEdit2);

private void treeList1_CustomNodeCellEdit(object sender, GetCustomNodeCellEditEventArgs e) {
    TreeList treeList = sender as TreeList;
    if(e.Node.Id != TreeList.NewItemNodeId && e.Column == employeeColumn && treeList.GetRowCellValue(e.Node, e.Column).ToString() == "Arthur Miller") {
        e.RepositoryItem = repositoryItemTextEdit2;
    }
}

Unbound Columns 未绑定的列

如果您需要一个不与特定数据源值关联的列(带有图像),请使用 RepositoryItemPictureEdit 对象创建一个未绑定的列作为就地编辑器。处理 TreeList.CustomUnboundColumnData 事件以向此列提供图像。

HTML Formatting HTML 格式

使用 TreeList.HtmlImages 集合和 Image HTML 标签将图像嵌入到单元格中。请注意,此方法使单元格不可编辑。

treeList1.HtmlImages = svgImageCollection1;
treeList1.RowHeight = 60;
TreeListColumn unbound = new TreeListColumn();
unbound.UnboundDataType = typeof(string);
unbound.FieldName = "unboundImageColumn";
unbound.Visible = true;
unbound.Caption = "Icon";
treeList1.Columns.Add(unbound);
RepositoryItemHypertextLabel htLabel = new RepositoryItemHypertextLabel();
htLabel.HtmlImages = svgImageCollection1;
treeList1.RepositoryItems.Add(htLabel);
unbound.ColumnEdit = htLabel;
treeList1.CustomUnboundColumnData += TreeList1_CustomUnboundColumnData;

private void TreeList1_CustomUnboundColumnData(object sender, DevExpress.XtraTreeList.TreeListCustomColumnDataEventArgs e) {
    if (e.Column.Caption == "Icon") {
        //image from a collection
        e.Value = "<image=add_32x32.png>";
        //image from resources
        //e.Value = "<image=#_589812_200>";
    }
}

Draw a Cell 绘制单元格

处理 CustomDrawNodeCell 事件以重新绘制单元格,并绘制自定义图像和形状。在此示例中,在包含“Arthur Miller”的单元格中绘制了一张图像。

在这里插入图片描述

private void treeList1_CustomDrawNodeCell(object sender, CustomDrawNodeCellEventArgs e) {
    TreeList treeList = sender as TreeList;
    if (e.Node.Id != TreeList.NewItemNodeId && e.Column == employeeColumn && treeList.GetRowCellValue(e.Node, e.Column).ToString() == "Arthur Miller") {
        e.Cache.DrawImage(imageCollection1.Images[0], e.Bounds.X + offsetX, e.Bounds.Y + offsetY);
    }
}

Node Indents 节点缩进

节点缩进是控件的边界与节点的第一个单元格的边界之间的距离。TreeList.TreeLevelWidth 属性指定根节点的此距离。

在这里插入图片描述

Node Checkboxes and Radio Buttons Node 复选框和单选按钮

您可以在某些树级别向 TreeList 节点添加复选框或单选按钮。

在这里插入图片描述
要设置或检索节点检查状态,请使用 TreeList 控件的方法。在绑定模式下,您可以将节点检查状态与数据源字段同步。有关更多信息,请参阅以下帮助主题:节点检查 - 复选框和单选按钮。

Preview Sections 预览部分

预览部分是显示在节点下的所有列中的不可编辑注释。
在这里插入图片描述
有关更多信息,请参阅以下帮助主题:预览部分。

Examples 例子

  • 如何:遍历节点并计算特定级别的节点数
  • 如何:循环访问节点和折叠特定节点
  • 如何:创建自定义节点并指定各个节点的高度
  • 如何:启用自动高度调整

http://www.kler.cn/news/360989.html

相关文章:

  • 时间序列预测(六)——循环神经网络(RNN)
  • 07 实战:视频捕获
  • 【系统架构设计师】专题:嵌入式系统考点梳理
  • 排序(1)
  • git的学习使用(认识工作区,暂存区,版本区。添加文件的方法)
  • RabbitMQ异常
  • PyTorch模型转换ONNX 入门
  • 24下河南秋季教资认定保姆级教程
  • 【YOLO系列】YOLO11原理和深入解析——待完善
  • 《深度学习》Dlib 人脸应用实例 性别年龄预测 案例实现
  • 传输层协议UDP详解
  • 【OpenGauss源码学习 —— (VecSortAgg)】
  • 集合分类及打印的方式
  • SDUT数据结构与算法第四次机测
  • Prometheus 告警
  • MySQL实现主从同步
  • 一个汉字占几个字节、JS中如何获得一个字符串占用多少字节?
  • 前端性能优化之加载篇
  • ubuntu安装boost、x264、FFMPEG
  • 前端项目中遇到的技术问题