TreeNode.具体点!
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/26 12:51:16
TreeNode.具体点!
TreeNode.具体点!
TreeNode.具体点!
在此网站中有详细解释http://msdn.microsoft.com/zh-cn/system.windows.forms.treenode.tag(VS.90).aspx 如下:
Tag 属性
.NET Framework 类库
TreeNode..::.Tag 属性
获取或设置包含树节点有关数据的对象.
命名空间: System.Windows.Forms
程序集: System.Windows.Forms(在 System.Windows.Forms.dll 中)
语法
_
_
Public Property Tag As Object
\x09Get
\x09Set[BindableAttribute(true)][TypeConverterAttribute(typeof(StringConverter))]public Object Tag { get; set; }[BindableAttribute(true)]
[TypeConverterAttribute(typeof(StringConverter))]
public:
property Object^ Tag {
\x09Object^ get ();
\x09void set (Object^ value);
}[]
[]
member Tag : Object with get, set
属性值
类型:System..::.Object
Object,包含有关树节点的数据. 默认为nullNothingnullptrnull 引用(在 Visual Basic 中为 Nothing).
备注
任何 Object 派生类型都可被指派给此属性. 如果此属性是通过 Windows 窗体设计器设置的,则只能指派文本.
示例
下面的代码示例创建一个要为其分配子树节点的根树节点. 将 ArrayList 中的每个
Customer
对象的一个子树节点以及分配给
Customer
对象的每个
Order
对象的一个子树节点添加到根树节点. 将
Customer
对象分配给 Tag 属性,并将表示
Customer
对象的树节点用 Orange 文本显示. 本示例要求已定义
Customer
和
Order
对象,Form 上具有 TreeView 控件,还要求有一个名为
customerArray
的 ArrayList,其中包含
Customer
对象.
Public Class Customer
Public CustomerOrders As ArrayList
Public CustomerName As String
Public Sub New(myName As String)
CustomerName = myName
CustomerOrders = New ArrayList()
End Sub 'New
End Class 'Customer
Public Class Order
Public OrderID As String
Public Sub New(myOrderID As String)
Me.OrderID = myOrderID
End Sub 'New
End Class 'Order
Public Sub AddRootNodes()
' Add a root node to assign the customer nodes to.
Dim rootNode As TreeNode
rootNode = New TreeNode()
rootNode.Text = "CustomerList"
' Add a main root treenode.
myTreeView.Nodes.Add(rootNode)
' Add a root treenode for each Customer object in the ArrayList.
Dim myCustomer As Customer
For Each myCustomer In customerArray
' Add a child treenode for each Order object.
Dim i As Integer = 0
Dim myTreeNodeArray(4) As TreeNode
Dim myOrder As Order
For Each myOrder In myCustomer.CustomerOrders
myTreeNodeArray(i) = New TreeNode(myOrder.OrderID)
i += 1
Next myOrder
Dim customerNode As New TreeNode(myCustomer.CustomerName, _
myTreeNodeArray)
' Display the customer names with and Orange font.
customerNode.ForeColor = Color.Orange
' Store the Customer object in the Tag property of the TreeNode.
customerNode.Tag = myCustomer
myTreeView.Nodes(0).Nodes.Add(customerNode)
Next myCustomer
End Sub
public class Customer{ public ArrayList CustomerOrders; public string CustomerName; public Customer(string myName) { CustomerName = myName; CustomerOrders = new ArrayList(); }}public class Order{ public string OrderID; public Order(string myOrderID ) { this.OrderID = myOrderID; }} public void AddRootNodes(){ // Add a root node to assign the customer nodes to. TreeNode rootNode = new TreeNode(); rootNode.Text = "CustomerList"; // Add a main root treenode. myTreeView.Nodes.Add(rootNode); // Add a root treenode for each 'Customer' object in the ArrayList. foreach(Customer myCustomer in customerArray) { // Add a child treenode for each Order object. int i = 0; TreeNode[] myTreeNodeArray = new TreeNode[5]; foreach(Order myOrder in myCustomer.CustomerOrders) { myTreeNodeArray[i] = new TreeNode(myOrder.OrderID); i++; } TreeNode customerNode = new TreeNode(myCustomer.CustomerName, myTreeNodeArray); // Display the customer names with and Orange font. customerNode.ForeColor = Color.Orange; // Store the Customer object in the Tag property of the TreeNode. customerNode.Tag = myCustomer; myTreeView.Nodes[0].Nodes.Add(customerNode); }}
ref class Customer
{
public:
ArrayList^ CustomerOrders;
String^ CustomerName;
Customer( String^ myName )
{
CustomerName = myName;
CustomerOrders = gcnew ArrayList;
}
};
ref class Order
{
public:
String^ OrderID;
Order( String^ myOrderID )
{
this->OrderID = myOrderID;
}
};
void AddRootNodes()
{
// Add a root node to assign the customer nodes to.
TreeNode^ rootNode = gcnew TreeNode;
rootNode->Text = "CustomerList";
// Add a main root treenode.
myTreeView->Nodes->Add( rootNode );
// Add a root treenode for each 'Customer' object in the ArrayList.
IEnumerator^ myEnum = customerArray->GetEnumerator();
while ( myEnum->MoveNext() )
{
Customer^ myCustomer = safe_cast(myEnum->Current);
// Add a child treenode for each Order object.
int i = 0;
array^myTreeNodeArray = gcnew array(5);
IEnumerator^ myEnum = myCustomer->CustomerOrders->GetEnumerator();
while ( myEnum->MoveNext() )
{
Order^ myOrder = safe_cast(myEnum->Current);
myTreeNodeArray[ i ] = gcnew TreeNode( myOrder->OrderID );
i++;
}
TreeNode^ customerNode = gcnew TreeNode( myCustomer->CustomerName,myTreeNodeArray );
// Display the customer names with and Orange font.
customerNode->ForeColor = Color::Orange;
// Store the Customer Object* in the Tag property of the TreeNode.
customerNode->Tag = myCustomer;
myTreeView->Nodes[ 0 ]->Nodes->Add( customerNode );
}
}
版本信息
.NET Framework
受以下版本支持:4、3.5、3.0、2.0、1.1、1.0
.NET Framework Client Profile
受以下版本支持:4、3.5 SP1
平台
Windows 7, Windows Vista SP1 或更高版本, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008(不支持服务器核心), Windows Server 2008 R2(支持 SP1 或更高版本的服务器核心), Windows Server 2003 SP2
.NET Framework 并不是对每个平台的所有版本都提供支持.有关支持的版本的列表,请参见.NET Framework 系统要求.
请参见
参考
TreeNode 类
System.Windows.Forms 命名空间
Object