private void LoadTree()
{
DataTable tbl = new DataTable();
tbl = oraConnector.ExecQuery("select account_id, parent,
type, name from account");
//Use a DataSet to manage the data
DataSet ds = new DataSet();
ds.Tables.Add(tbl);
//add a relationship
ds.Relations.Add("rsParentChild",
ds.Tables[0].Columns["account_id"],
ds.Tables[0].Columns["parent"]);
foreach (DataRow dr in tbl.Rows)
{
if (dr["parent"] == DBNull.Value)
{
TreeNode root = new TreeNode(dr["name"].ToString());
root.Tag = dr["type"].ToString();
treeView.Nodes.Add(root);
PopulateTree(dr, root);
}
}
// treeView.ExpandAll();
}
public void PopulateTree(DataRow dr, TreeNode pNode)
{
foreach (DataRow row in dr.GetChildRows("rsParentChild"))
{
TreeNode cChild = new TreeNode(row["NAME"].ToString());
cChild.Tag = row["TYPE"].ToString();
pNode.Nodes.Add(cChild);
//Recursively build the tree
PopulateTree(row, cChild);
}
}
{
DataTable tbl = new DataTable();
tbl = oraConnector.ExecQuery("select account_id, parent,
type, name from account");
//Use a DataSet to manage the data
DataSet ds = new DataSet();
ds.Tables.Add(tbl);
//add a relationship
ds.Relations.Add("rsParentChild",
ds.Tables[0].Columns["account_id"],
ds.Tables[0].Columns["parent"]);
foreach (DataRow dr in tbl.Rows)
{
if (dr["parent"] == DBNull.Value)
{
TreeNode root = new TreeNode(dr["name"].ToString());
root.Tag = dr["type"].ToString();
treeView.Nodes.Add(root);
PopulateTree(dr, root);
}
}
// treeView.ExpandAll();
}
public void PopulateTree(DataRow dr, TreeNode pNode)
{
foreach (DataRow row in dr.GetChildRows("rsParentChild"))
{
TreeNode cChild = new TreeNode(row["NAME"].ToString());
cChild.Tag = row["TYPE"].ToString();
pNode.Nodes.Add(cChild);
//Recursively build the tree
PopulateTree(row, cChild);
}
}
вопрос по структуре таблицы.
ОтветитьУдалитьзачем type,и что там должно быть?