I have a table with two columns and I want to display them hierarchically in a tree view with a Oracle database binding using Windows Forms (.NET 4.0)
ORGID, PARENTID
======================
1 -
2 1
3 1
4 3
.....
Being ORGID the parent, and the PARENTID the child (which can also be a parent).
I've tried this:
public partial class OrgHierarchy : Form
{
DataSet ds = new DataSet();
TreeNode parentNode = null;
DataSet RunQuery(String Query)
{
DataSet ds = new DataSet();
OracleConnection con = new OracleConnection(OrgScheme.GetConnectionString());
DataTable dt = new DataTable();
OracleCommand cmd = new OracleCommand();
cmd.CommandText = Query;
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
con.Open();
OracleDataAdapter da = new OracleDataAdapter(cmd);
ds = new DataSet();
da.Fill(ds);
return ds;
}
void CreateNode(TreeNode node)
{
DataSet ds = RunQuery("select orgid ,parentid ... 0 and parentid=" + node.Value +" order by parentid,orgid");
if (ds.Tables[0].Rows.Count == 0)
{
return;
}
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
TreeNode tnode = new TreeNode(ds.Tables[0].Rows[i][1].ToString(), ds.Tables[0].Rows[i][0].ToString());
tnode.SelectAction = TreeNodeSelectAction.Expand;
node.ChildNodes.Add(tnode);
CreateNode(tnode);
}
}
public OrgHierarchy()
{
InitializeComponent();
DataSet ds = RunQuery("select orgid ,parentid .... and parentid is null");
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
TreeNode root = new TreeNode(ds.Tables[0].Rows[i][1].ToString(), ds.Tables[0].Rows[i][0].ToString());
root.SelectAction = TreeNodeSelectAction.Expand;
CreateNode(root);
OrgTree.Nodes.Add(root);
}
}
}
I have a number of errors:
Error 1 'System.Windows.Forms.TreeNode' does not contain a definition for 'Value' and no extension method 'Value' accepting a first argument of type 'System.Windows.Forms.TreeNode' could be found (are you missing....
Error 2 The best overloaded method match for 'System.Windows.Forms.TreeNode.TreeNode(string, System.Windows.Forms.TreeNode[])' has some invalid arguments
Help please? I think I'm using Web controls (.Value) which I can't do using WinForms.