Troubles with TreeViews

M

Mike Demmons

I am experiencing strange behavior from the Standard
Windows Forms TreeView control.

My application retrieves a dataset from a Web-Service. If
the download was sucessful, I call the Dataset.WriteXml()
method to persist the dataset to the local disk. The
next time the app runs, I check to see if the Xml file
exists, and if it does, I call ReadXml() instead of going
to the webservice. (The data doesn't change often).

From the dataset, I generate a six-level treeview.

Everything works fine the first time, until I choose to
refresh the dataset, and re-generate the treeview. The
tree goes blank, except for a single plus/minus image.
When I click on the 'node', it seems to expand, but no
data is being displayed.

I am doing the following when I refresh the data:
1. Clear the contents of the dataset
2. Retrieve the data again from the web-service
3. Remove all nodes from the tree-view
4. Re-build all nodes from the dataset

This process works great when I first run the program,
but when I try to refresh the dataset while it is
running, it gives me grief.

Anyone have any ideas? Sorry for the long winded
explanation. Any help would be appreciated.

........../mike
 
J

Julia Lerman

What basic functions are you using for each of the four steps. I'm not
asking for thousands of lines of codes, just a basic description.

Julie Lerman
..NET MVP
 
M

Mike Demmons

Step 1.Clear Dataset
CODE= UIDataset.Clear();

Step 2.Retreive data from web service
CODE= UIDataset.Merge(ws.GetDataSet());

Step 3.Remove all nodes from treeview
CODE= treeView1.Nodes.Clear();

Step 4.Rebuild all nodes from dataset
CODE= foreach(DataRow dr1 in UIDataset.Tables[0].Rows)
{ TreeNode node1 = new TreeNode(data from dr1);
treeView1.Nodes.Add(node1);
foreach(DataRow dr2 in dr1.GetChildRows())
{ TreeNode node2 = new TreeNode(data from dr2)
node1.Nodes.Add(node2);
foreach(DataRow dr3 in dr2.GetChildRows())
{ etc.... etc... etc.... }
}
}

Hope that helps. If you need more information, just let
me know. You can email me at:
mdemmonsATcaltech-corpDOTcom
(replace AT with @ and DOT with .)

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top