You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VB.NET DevExpress TreeList如何让新增节点显示在顶部?

在DevExpress TreeList中通过代码将新增节点置于顶部的解决方案

你设置的TreeList1.OptionsView.NewItemRowPosition属性只对TreeList内置的可编辑新行生效——就是那个用来手动输入新增数据的固定行,对通过AppendNode代码添加的自定义节点不起作用,所以不会改变你新增节点的位置。

要让代码添加的节点显示在顶部,有两种直接的实现方式:

方式一:直接插入到根节点集合的首位

用InsertNode方法代替AppendNode,指定插入位置为索引0(根节点集合的第一个位置):

Dim newNode As TreeListNode = TreeList1.InsertNode(New Object() {"Sold", size, price, startTime.ToShortTimeString()}, 0, -1)

参数说明:

  • 第二个参数0:表示插入到根节点集合的第1个位置(索引从0开始)
  • 第三个参数-1:表示该节点是根节点,无父节点

方式二:先添加再移动节点到顶部

如果已经用了AppendNode,可以在添加后调用Move方法把节点移到首位:

Dim newNode As TreeListNode = TreeList1.AppendNode(New Object() {"Sold", size, price, startTime.ToShortTimeString()}, -1)
TreeList1.Nodes.Move(newNode, 0)

额外注意事项

如果你的TreeList开启了列排序,移动或插入的节点可能会被排序规则重新排列位置。这种情况下需要先临时关闭排序,操作完成后再按需恢复:

' 临时关闭排序功能
TreeList1.OptionsBehavior.SortOnColumnClick = False
TreeList1.Columns.ClearSorting()

' 执行节点插入/移动操作
Dim newNode As TreeListNode = TreeList1.InsertNode(New Object() {"Sold", size, price, startTime.ToShortTimeString()}, 0, -1)

' 如需恢复排序,重新设置目标列的排序规则
' TreeList1.Columns("你的排序列名").SortOrder = DevExpress.Data.ColumnSortOrder.Ascending

内容的提问来源于stack exchange,提问作者Omid Al

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 11:15:13