【发布时间】:2015-02-18 20:23:47
【问题描述】:
我是 C# 新手,在语法和传递对象方面遇到问题。我正在构建一个表格,其中包含商店的树形视图和每个商店的客户列表视图。当我单击表单上的按钮时,会调用“OnStoreAdd”并创建存储对象。如何将该对象传递给“AddStoreNode(object?tag?)”?
namespace CustomerInfoObjects
{
public class Store
{
private List<Customer> _customers = new List<Customer>();
public List<Customer> Customers
{
get { return _customers; }
set { _customers = value; }
}
private string _name = string.Empty;
public string Name
{
get { return _name; }
set { _name = value; }
}
}
}
namespace DomainObjects
{
public class CustomerList : List<Customer> { }
public class StoreToCustomerListDictionary : Dictionary<Store, CustomerList> { }
public class CustomerInfoDocument
{
private StoreToCustomerListDictionary _storeToCustomerList = new StoreToCustomerListDictionary();
public StoreToCustomerListDictionary StoreToCustomerList
{
get { return _storeToCustomerList; }
set { _storeToCustomerList = value; }
}
}
}
namespace BusinessLayer
{
public static class CustomerMgr
{
private static CustomerInfoDocument _document = new CustomerInfoDocument();
public static bool AddStore(string storeName)
{
Store store = new Store();
store.Name = storeName;
_document.StoreToCustomerList.Add(store, null);
return true;
}
}
}
namespace UILayer
{
public partial class StoreTreeControl : UserControl
{
public StoreTreeControl()
{
InitializeComponent();
}
public void AddStoreNode(Store object? ) //What type of argument?
{
TreeNode node = _tvwStores.Nodes.Add(store.Name);
node.Tag = store;
_tvwStores.SelectedNode = node;
}
private void OnStoreAdd(object sender, System.EventArgs e)
{
StorePropertiesForm f = new StorePropertiesForm();
if (f.ShowDialog() != DialogResult.OK)
return;
if (!CustomerMgr.AddStore(f.StoreName))
{
MessageBox.Show("Store name should no be blank");
return;
}
AddStoreNode(?); //What argument would I use here?
}
}
}
我不知道如何将新的商店对象传递给 AddStoreNode 方法。 AddStoreNode 方法中的标记使我的列表视图可以访问树视图节点。我需要在 StoreAdd 方法中使用另一个标签吗?
任何可以为我指明正确方向的信息将不胜感激!
【问题讨论】:
-
对我来说毫无意义。为什么你会有一个类商店,它有一个属性客户和一个字典(商店,客户)?
标签: c# .net object treeview parameter-passing