c#treeViewバインドセット
2286 ワード
// public static List ConvertToTreeViewData(
///
/// TreeView
///
///
///
///
///
public static bool InsertDataToTreeView(TreeView treeView, List treeDatas,int pID) {
TreeViewTool.pID = pID;
int len = treeDatas.Count;
int j = 0;
for (int i = 0; i < len; i++) {
if ((int)treeDatas[i].PID == pID) {
treeView.Nodes.Add(treeDatas[i].Name.ToString());
treeView.Nodes[j].Tag = treeDatas[i].Id;
j++;
}
}
for (int i = 0; i < treeView.Nodes.Count; i++) {
TempTreeView(treeView.Nodes[i], treeDatas);
}
return false;
}
private static void TempTreeView(TreeNode tn, List treeDatas) {
int len = treeDatas.Count;
int j = 0;
for (int i = 0; i < len; i++) {
if ((int)treeDatas[i].PID != pID) {
if ((int)treeDatas[i].PID == (int)tn.Tag) {
tn.Nodes.Add(treeDatas[i].Name.ToString());
tn.Nodes[j].Tag = treeDatas[i].Id;
TempTreeView(tn.Nodes[j], treeDatas);
j++;
}
}
}
}
上の最初のメソッドを呼び出し、エンティティクラスを使用する必要があります.
public class TreeViewData {
Object id;
///
///
///
public Object Id {
get { return id; }
set { id = value; }
}
Object name;
///
///
///
public Object Name {
get { return name; }
set { name = value; }
}
Object pID;
///
///
///
public Object PID {
get { return pID; }
set { pID = value; }
}
}