473,386 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Fill a tree view with a stored procedure

I have a stored procedure that returns a dataset. I want this dataset to
fill a tree view.

Here is the Stored Procedure Query

SELECT Product.Product_#, Product.Part_Number, Status.Status,
Traveler_Step.Step, Station.Station_Name
FROM Product INNER JOIN
Traveler_Step ON Product.Traveler_Step_# =
Traveler_Step.Traveler_Step_# INNER JOIN
Station ON Traveler_Step.Station_# = Station.Station_#
INNER JOIN
Status ON Product.Status_# = Status.Status_#
WHERE (Station.Station_# = 8)
Here is a typical result

Product_# Part_Number Status Step
Station_Name
----------- -------------------- -------------------- ----------- --------------------
48 123789 Active 40 Hot Mill
231 U06107LG Active 20 Hot Mill
I would like the tree view master node to be Station Name, the first child
node to be the Part Number with an icon next to it indicating the status,
next child node under part_number the Step and Product_#.

So this is what I am after

HotMill
|
-----(Active icon) 123789
|
------40
|
------48

I understand I need hierarchical data, but the stored procedure only returns
one dataset. How can I do this?

Thanks.

John
Mar 1 '06 #1
2 4075
Hi John
Suppose you populate your dataTable and you are ready to fill your tree
using FillTree :

private void FillTree(DataTable table)
{
foreach (DataRow row in table.Rows)
AddRow(row);
}

private void AddRow(DataRow row)
{
TreeNode stationNode =
FindStationNode(row["Station_Name"].ToString());
if (stationNode == null)
AddStationNode(row["Station_Name"]);

AddToStation(stationNode, row);
}

private void AddToStation(TreeNode stationNode, DataRow row)
{
TreeNode node = new TreeNode();
node.Text = row["Part_Number"].ToString();
if (row["Status"].ToString() == "Active")
node.ImageIndex = 0;
else
node.ImageIndex = 1;
node.Nodes.Add(row["Step"].ToString());
node.Nodes.Add(row["Product_#"].ToString());

stationNode.Nodes.Add(node);
}

private void AddStationNode(string name)
{
treeView1.Nodes.Add(name);
}

private TreeNode FindStationNode(string p)
{
foreach (TreeNode node in treeView1.Nodes)
if (node.Text == p)
return node;
return null;
}

Best Regards,
A.Hadi

Mar 1 '06 #2
I'm sorry.I thought I am in C# group. (VB version) :
Private Sub FillTree(ByVal table As DataTable)

For Each row As DataRow In table.Rows
AddRow(row)
Next
End Sub

Private Sub AddRow(ByVal row As DataRow)

Dim stationNode As TreeNode =
FindStationNode(row("Station_Name").ToString())
If stationNode Is Nothing Then
AddStationNode(row("Station_Name"))
End If
AddToStation(stationNode, row)
End Sub

Private Sub AddToStation(ByVal stationNode As TreeNode, ByVal row
As DataRow)

Dim node As TreeNode = New TreeNode()
node.Text = row("Part_Number").ToString()
If (row("Status").ToString() = "Active") Then
node.ImageIndex = 0
Else
node.ImageIndex = 1
node.Nodes.Add(row("Step").ToString())
node.Nodes.Add(row("Product_#").ToString())
End If

stationNode.Nodes.Add(node)
End Sub

Private Sub AddStationNode(ByVal name As String)

TreeView1.Nodes.Add(name)
End Sub

Private Function FindStationNode(ByVal name As String) As TreeNode

For Each node As treenode In treeView1.Nodes
If node.Text = name Then
Return node
End If
Next
Return Nothing
End Function

Thanks

Mar 1 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: MD | last post by:
I am trying to create a dynamic SQL statement to create a view. I have a stored procedure, which based on the parameters passed calls different stored procedures. Each of this sub stored procedure...
10
by: serge | last post by:
Using "SELECT * " is a bad practice even when using a VIEW instead of a table? I have some stored procedures that are identical with the difference of one statement in the WHERE clause. If I...
1
by: Bob Sparks | last post by:
I found this in a FAQ How can I locate the dependencies of an SQL procedure? A: The dependencies are stored in the package of the stored procedure. After creating a stored procedure, determine...
2
by: Justin | last post by:
I am creating a web app for a client in VS.NET using ASP.NET with C#. I need to query three tables in a database using one parameter and display the results on the page. my question is should I use...
9
by: Nikolay Petrov | last post by:
How to fill DataSet from stored procedure?
5
by: moondaddy | last post by:
I have a website where cataloge pages are populated by calling a stored procedure on sql server. I use the sql data adapter's fill method to call this stored procedure and fill the dataset. about...
10
by: Rich | last post by:
I have a stored procedure on Sql Server2k. I can fill a data table which I can append to a dataset using an ADODB recordset object which gets populated from a command object that runs the sp. I...
0
by: negmat | last post by:
Does anyone know how exactly the sub-tree cost is calculated and whether it should be used as an indication of query/stored procedure performance? I used to think (although I could never find a...
1
by: apothecary | last post by:
Hello Newbie here. Is there a way of creating a VIEW...using a stored procedure. I am basically trying to create a view to return some data that I am getting using a stored procedure. I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.