标题:[求助]一段小程序,请您指点一下
只看楼主
wujincai
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2006-3-21
 问题点数:0 回复次数:4 
[求助]一段小程序,请您指点一下

在MSDN上看到的一个关于treeview类的操作使用方法示例,在机子上运行了一下有点问题,百思不得其解.

------------------------------------------------
本示例假定有一个 Customer 对象,它可以存放 Order 对象的集合。还假定在应用程序目录中有一个名为 MyWait.cur 的光标文件,并已在 Form 上创建了 TreeView 控件的一个实例。


// Create a new ArrayList to hold the Customer objects.
private ArrayList customerArray = new ArrayList();

private void FillMyTreeView()
{
// Add customers to the ArrayList of Customer objects.
for(int x=0; x<1000; x++)
{
customerArray.Add(new Customer("Customer" + x.ToString()));
}

// Add orders to each Customer object in the ArrayList.
foreach(Customer customer1 in customerArray)
{
for(int y=0; y<15; y++)
{
customer1.CustomerOrders.Add(new Order("Order" + y.ToString()));
}
}

// Display a wait cursor while the TreeNodes are being created.
Cursor.Current = new Cursor("MyWait.cur");

// Suppress repainting the TreeView until all the objects have been created.
treeView1.BeginUpdate();

// Clear the TreeView each time the method is called.
treeView1.Nodes.Clear();

// Add a root TreeNode for each Customer object in the ArrayList.
foreach(Customer customer2 in customerArray)
{
treeView1.Nodes.Add(new TreeNode(customer2.CustomerName));

// Add a child treenode for each Order object in the current Customer object.
foreach(Order order1 in customer2.CustomerOrders) //注意了,我在这里出现了问题
{
treeView1.Nodes[customerArray.IndexOf(customer2)].Nodes.Add(
new TreeNode(customer2.CustomerName + "." + order1.OrderID));
}
}

// Reset the cursor to the default for all controls.
Cursor.Current = Cursors.Default;

// Begin repainting the TreeView.
treeView1.EndUpdate();
}

---------------------------------------------------------------------------------------------------------
有谁能帮忙把那个几Customer对象,order对象类的具体定义描述出来吗?
我的是这样的,不过通不过编译:
public class Customer
{
public Customer(string theCustomerName)
{
CustomerName=theCustomerName;
CustomerOrders=new CustomerOrder();
}


public CustomerOrder CustomerOrders;
public string CustomerName;
}

public class CustomerOrder
{
public CustomerOrder()
{
}

public void Add(Order orders)
{
orderkeeper[i]=orders.GetOrder();
}
private string[] orderkeeper;
static int i=0;
}

public class Order
{
public Order(string odr)
{
this.myorder=odr;
}

public string GetOrder()
{
return this.myorder;
}


private string myorder;
}

----------------------------------


谢谢你的关注~!

搜索更多相关主题的帖子: class blank 应用程序 target 
2006-03-21 20:19
wujincai
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2006-3-21
得分:0 
自已先顶一下~
2006-03-21 20:44
wujincai
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2006-3-21
得分:0 
再顶
2006-03-21 20:44
ytyt654
Rank: 2
等 级:新手上路
威 望:4
帖 子:195
专家分:0
注 册:2006-2-13
得分:0 
有谁能帮忙把那个几Customer对象,order对象类的具体定义描述出来吗?
我的是这样的,不过通不过编译:
public class Customer
{
public Customer(string theCustomerName)
{
CustomerName=theCustomerName;
CustomerOrders=new ArrayList();
}


public ArrayList CustomerOrders;
public string CustomerName;
}

//public class CustomerOrder
//{
// public CustomerOrder()
// {
// }

// public void Add(Order orders)
// {
// orderkeeper[i]=orders.GetOrder();
// }
// private string[] orderkeeper;
// static int i=0;
//}

public class Order
{
public Order(string odr)
{
this.myorder=odr;
}

public string GetOrder()
{
return this.myorder;
}


private string myorder;
}


2006-03-22 13:43
wujincai
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2006-3-21
得分:0 

谢谢楼上的大虾~!
我这就试试!
Thanks again~!

2006-03-22 19:26



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-51888-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.820546 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved