Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

treeview w/ drilldown / into data 1

Status
Not open for further replies.

codecomm

Programmer
Feb 14, 2007
121
US
What I'd like to do is use a tree view on some route to help allow users to drill down into their data.

For instance, we have a table w/ 100 numbers, and they're nvarchar(100).

For simplicity sake, 50 start with D1, and the other 50 start with E1.

Under the 50 that start with D1, they are grouped by a dot and some more characters up to the next dot:

1. D1.01

2. D1.02

3. D1.03

4. D1.04

5. D1.05


When the page first loads, the 2 nodes would show:

D1

E1


..and if the user clicked D1, they'd see new nodes which took the next chars up to any next "dot" and listed the groupings/nodes like above.

1. D1.01

2. D1.02

3. D1.03

4. D1.04

5. D1.05


..and if the user clicked on D1.02, and the data would show like:

1. D1.02.01

2. D1.02.02

3. D1.02.03


...and if the user clicked on D1.02.03, they would see new nodes of:

1. D1.02.03.001

2. D1.02.03.02

3. D1.02.03.03B

..or something like that. Basically, each time the user clicks the node, we show a "dot" and two more characters...or up to the next "dot".

I have the tree view working now, but it's pretty much a one-for-one, and that's not very helpful for this scenario.

Thanks!
 
IF is this the output you want
[tt]
Root
+-D1
+-D1.01
+-D1.01.01
+-D1.01.01.123
+-D1.01.01.456
+-D1.01.01.ABC
+-D1.01.02
+-D1.01.02.123
+-D1.01.02.456
+-D1.01.02.ABC
+-D1.02
+-D1.02.01
+-D2.01.01.123
+-D2.01.01.456
+-D2.01.01.ABC
+-D1.02.02
+-D2.01.02.123
+-D2.01.02.456
+-D2.01.02.ABC
+-E1
+-E1.01
+-E1.01.01
+-E1.01.01.123
+-E1.01.01.456
+-E1.01.01.ABC
+-E1.01.02
+-E1.01.02.123
+-E1.01.02.456
+-E1.01.02.ABC
+-E1.02
+-E1.02.01
+-E2.01.01.123
+-E2.01.01.456
+-E2.01.01.ABC
+-E1.02.02
+-E2.01.02.123
+-E2.01.02.456
+-E2.01.02.ABC
[/tt]
and this is the data you get
[tt]
ID
-------------
D1.01.01.123
D1.01.01.456
D1.01.01.ABC
D1.01.02.123
D1.01.02.456
D1.01.02.ABC
D1.02.01.123
D1.02.01.456
D1.02.01.ABC
D1.02.02.123
D1.02.02.456
D1.02.02.ABC
E1.01.01.123
E1.01.01.456
E1.01.01.ABC
E1.01.02.123
E1.01.02.456
E1.01.02.ABC
E1.02.01.123
E1.02.01.456
E1.02.01.ABC
E1.02.02.123
E1.02.02.456
E1.02.02.ABC
[/tt]
you will need to parse the data into heirachal data. there are a number of ways to do this.
1. cycle through the datatable and bulid and xml tree. you'll need to compare the previous value to the current value to know when/where to append a new child now.
2. get the string of the xml and use that as the datasource for the XMLDataSource.
3. set the XMLDataSource as the TreeView.DataSource.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
thanks jmeckley!

yes, that would be correct.

I guess I need to get on the heirarchical data route and understand what's going on to do it.

Thanks for the starter suggestions! That points me to what I need to do to get started!
 
jmeckley,

I saw this:

...not too sure if that will get me what I need, but I'll try. Any other suggestions are more than welcome!

This one is stumping me since I don't know how to approach the whole format of the string value and look up to the "dot" then go backwards and pull that value, and how to add child nodes.

Thanks!
 
I would assume that you get the data as a single property/column in an enumerated object. for simplicity sake it will either be a datatable with 1 column or something like [tt]IList<string>[/tt].
loop through this object and parse the string on the dot
Code:
public function string GetNodesAsXmlString()
{
   DataTable data = //get data;

   //create temp table
   DataTable t = new DataTable();
   t.columns.Add("section1");
   t.columns.Add("section2");
   t.columns.Add("section3");
   t.columns.Add("section4");

   //parse original data into new data
   foreach(DataRow row in results.Rows)
   {
      t.LoadDataRow(row[0].ToString().Split('.'));
   }

   //create xml string for GUI
   StringWriter sw = new StringWriter();
   XmlTextWriter xw = new XmlTextWriter(sw);
   
   xw.WriteStartDocument(); //create xml header
   xw.WriteStartElement("myTree"); //create root element <MyTree>

   foreach(DataRow row in t.Rows)
   {
     //append sections to the tree
   }
  
   xw.WriteEndElement(); //</MyTree>
   xw.Flush();
   xw.Close();
   sw.Flush();

   return sw.ToString();
}

//in gui
MyXmlDataSource.Xml = GetNodesAsXmlString();
I need to complete project this week, and so for some reason the foreach above is eluding me. But i wanted to get some code to point you in a possible direction.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top