我有3个具有以下数据格式的下拉列表。
Dropdown-1 Dropdown-2 Dropdown-3
----------- -------------- ---------------
Parent-1 Boy-1 Girl-1
Parent-2 Boy-2 Girl-2
Parent-3 Boy-3 Girl-3
基于下拉框中的选择;
如果我选择 来自Dropdown-1的Parent-2 来自Dropdown-2的Boy-1 来自Dropdown-3的Girl-2
然后我需要以下分层格式的结果:
Parent 1
Boy 1
Name 1:
Age 1:
Girl 1
Name 1:
Age 1:
Girl 2
Name 2:
Age 2:
Parent 2
Boy 1
Name 1:
Age 1:
Girl 1
Name 1:
Age 1:
Girl 2
Name 2:
Age 2:
需要您的支持。
预先感谢
kka_anand
答案 0 :(得分:0)
我尝试使用TreeView类,并且能够创建Parent和child对象。当我尝试创建Grantchild时。它在下面标记的区域中引发错误。任何修复它的建议。
// ============================================= ================
// Add a child treenode for each NameAge object in the current Gender object.
foreach (NameAge noOfNameAge in noOfParents.ParentOrder)
{
controllerOutput.Nodes[parentArray.IndexOf(noOfParents)].Nodes[genderArray.IndexOf(noOfGender)].Nodes.Add(
new TreeNode(noOfNameAge.NameAgeID));
}
// ============================================= ================
// Start of parent class.
public class Parent : System.Object
{
private string parentName = "";
protected ArrayList parentOrder = new ArrayList();
public Floor(string parentName)
{
this.floorName = parentName;
}
public string ParentName
{
get { return this.parentName; }
set { this.parentName = value; }
}
public ArrayList ParentOrder
{
get { return this.parentOrder; }
}
} // End of parent class.
// Start of gender (Boy/Girl) class.
public class Corridor : System.Object
{
private string genderID = "";
protected ArrayList genderOrder = new ArrayList();
public Gender(string genderid)
{
this.genderID = genderid;
}
public string GenderID
{
get { return this.genderID; }
set { this.genderID = value; }
}
public ArrayList GenderOrder
{
get { return this.genderOrder; }
}
} // End of gender class.
// Start of NameAge class.
public class NameAge : System.Object
{
private string nameageID = "";
protected ArrayList nameageOrder = new ArrayList();
public NameAge(string nameageid)
{
this.nameageID = nameageid;
}
public string NameAgeID
{
get { return this.NameAgeID; }
set { this.NameAgeID = value; }
}
public ArrayList NameAgeOrder
{
get { return this.nameageOrder; }
}
} // End of NameAge class.
private ArrayList parentArray = new ArrayList();
private ArrayList genderArray = new ArrayList();
private ArrayList nameageArray = new ArrayList();
private void FillControllerTreeView()
{
// Add parent to the ArrayList of Parent objects.
for (int x = 1; x <= Convert.ToInt32(DropDown-1.SelectedItem.ToString()); x++)
{
parentArray.Add(new Parent("Parent - " + x.ToString()));
}
// Add Gender(Boy/Girl) to each Parent object in the ArrayList.
foreach (Parent parent in parentArray)
{
for (int y = 1; y <= Convert.ToInt32(DropDown-2.SelectedItem.ToString()); y++)
{
parent.ParentOrder.Add(new Gender("Boy - " + y.ToString()));
}
for (int z = 1; z <= Convert.ToInt32(DropDown-3.SelectedItem.ToString()); z++)
{
parent.ParentOrder.Add(new Gender("Girl - " + z.ToString()));
}
}
foreach (NameAge nameage in nameageArray)
{
for (int y = 0; y <= 2; y++)
{
nameage.NameAgeOrder.Add(new NameAge("Light - " + y.ToString()));
}
nameage.NameAgeOrder.Add(new NameAge("AC - "));
}
controllerOutput.BeginUpdate();
controllerOutput.Nodes.Clear();
foreach (Parent noOfParents in parentArray)
{
controllerOutput.Nodes.Add(new TreeNode(noOfParents.ParentName));
// Add a child treenode for each gender object in the current Parent object.
foreach (Gender noOfGender in noOfParents.ParentOrder)
{
controllerOutput.Nodes[parentArray.IndexOf(noOfParents)].Nodes.Add(
new TreeNode(noOfGender.GenderID));
// Add a child treenode for each NameAge object in the current Gender object.
foreach (NameAge noOfNameAge in noOfParents.ParentOrder)
{
controllerOutput.Nodes[parentArray.IndexOf(noOfParents)].Nodes[genderArray.IndexOf(noOfGender)].Nodes.Add(
new TreeNode(noOfNameAge.NameAgeID));
}
}
}
controllerOutput.EndUpdate();
}
谢谢