下面的示例访问了树状列表的根结点,并修改了“Sales and Marketing”部门的“Budget”列值。
TreeListColumn 的实例被用作列标识符 (在 TreeListNode.GetDisplayText、TreeListNode.GetValue 和 TreeListNode.SetValue 方法中)。
C# | 复制代码 |
---|---|
IEnumerator en = treeList1.Nodes.GetEnumerator(); TreeListColumn columnDep = treeList1.Columns["Department"]; TreeListColumn columnBudget = treeList1.Columns["Budget"]; while (en.MoveNext()) { TreeListNode childNode = (TreeListNode)en.Current; if(childNode.GetDisplayText(columnDep) == "Sales and Marketing") { decimal newBudget = (decimal)childNode.GetValue(columnBudget) / 2; childNode.SetValue(columnBudget, newBudget); } } |
Visual Basic | 复制代码 |
---|---|
Dim en As IEnumerator = TreeList1.Nodes.GetEnumerator() Dim ColumnDep As TreeListColumn = TreeList1.Columns("Department") Dim ColumnBudget As TreeListColumn = TreeList1.Columns("Budget") While en.MoveNext() = True Dim ChildNode As TreeListNode = CType(en.Current, TreeListNode) If ChildNode.GetDisplayText(ColumnDep) = "Sales and Marketing" Then Dim NewBudget As Decimal = CType(ChildNode.GetValue(ColumnBudget), Decimal) / 2 ChildNode.SetValue(ColumnBudget, NewBudget) End If End While |