hi all.
in my c#2005 winforms application i must load a treeview.
my table is very simple,only 2 columns, 1 for the description and 1 for the hirarchy
e.g -
MyFatherA 1
MySon1 1.1
MySon2 1.2
MyFatherB 2
MySon3 2.1
whats the best and fastest way to load my treeview

help with treeview
george33387
i need help building the recirsive function, based on my datatable structure.
thanks.
Luis Alonso Ramos
i gave you the exact structure in my first post,
but - here it is again:
the tablw has 2 columns:
column1 - description , column2 - hirarchy
e.g
Desc Hirarchy
FatherA 1
SonA 1.1
SonB 1.2
FatherB 2
etc etc....
mjhoagland
Hi
Would you like to tell us about your database structure, So we will be able to help you to the point.
Thank you
GoDaddy
Hi
Populate the TreeView in a seperate thread
Use Recersive function to load data in TreeView
Ariel Mon
Hi, is this what you are looking for
private void Load_Click(object sender, EventArgs e)
{
TreeNode MyFatherA = new TreeNode("MyFatherA");
MyFatherA.Nodes.Add("MySon1");
MyFatherA.Nodes.Add("MySon2");
TreeNode MyFatherB = new TreeNode("MyFatherB");
MyFatherB.Nodes.Add("MySon3");
MyFatherB.Nodes.Add("MySon4");
treeView1.Nodes.Add(MyFatherA);
treeView1.Nodes.Add(MyFatherB);
}
ivj
private
void Form1_Load(object sender, System.EventArgs e){
DataTable dt = GetTable();
foreach(DataRow dr in dt.Rows){
if(dr[1].ToString().IndexOf(".") == -1){
TreeNode tn =
new TreeNode(dr[0].ToString());tn.Nodes.Add(GetChildNodes(
new DataView(dt), dr[1].ToString()));treeView1.Nodes.Add(tn);
}
}
}
private TreeNode GetChildNodes(DataView dv , string hirarchy){
dv.RowFilter = "hirarchy LIKE '" + hirarchy + "*' AND hirarchy <> '"+ hirarchy +"'";
TreeNode tn =
new TreeNode(); foreach(DataRowView drv in dv){
tn.Text = drv[0].ToString();
tn.Nodes.Add(GetChildNodes(
new DataView(dv.Table), drv[1].ToString()));}
return tn;}
private DataTable GetTable(){
DataTable dt =
new DataTable();dt.Columns.Add("desc");
dt.Columns.Add("hirarchy");
dt.LoadDataRow(
new object[]{"FatherA","1"},true);dt.LoadDataRow(
new object[]{"SonA","1.1"},true);dt.LoadDataRow(
new object[]{"SonB","2.1"},true);dt.LoadDataRow(
new object[]{"SonAa","1.1.1"},true);dt.LoadDataRow(
new object[]{"FatherB","2"},true); return dt;}