index > Visual C# General > loading array in treeview

loading array in treeview

Hi,

I'm making an application in C# that speaks to an report server (reporting service 2005 delivered with SQL Server 2005).

In my application I have a treeview object, in that object I want to have the structure like it is on the Report Server. So far I've managed to create some code that lists the structure but it only goes one level deep:

[CODE]
ReportingService2005 rs = new ReportingService2005();
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
// get array with children from the root folder
CatalogItem[] items = rs.ListChildren("/", false);
foreach (CatalogItem item in items)
{
// add every item in the array to my treeview
cmbRapporten.Nodes.Add(item.Name);
// get array with children from the current folder (item.Name.ToString())
CatalogItem[] childs = rs.ListChildren("/" + item.Name.ToString(), false);
foreach (CatalogItem child in childs)
{
// put every child in the correct node
cmbRapporten.Nodes[counter].Nodes.Add(child.Name);
}
counter++;
}
[CODE]

Pretty cool and almost what I wanted but what if a folder in the root has multiple subfolders that also contains reports. How would I do that. I can get the type of the item with the property item.type so I can check if it is a report or a folder.

I suppose I should write a method with passing some variables like the String with the path on the report server where it should look, and some ints because I have to know in wich node I am in...

If anyone can get me some help it would be really appreciated!

Many thanks in advance,

greetings
DanteTheCoolOne

I did this for RS 2000 but the code should be about the same. I also don't remember the exact function names so I'll give you the pseudo-code

void BuildTree ( string catalogPath, TreeNode parentNode )
{
//Get the catalog items (if path is empty then use root otherwise it
//is a folder path)
CatalogItem[] items = Get the catalog items (not recursive)

//Get the parent node collection (the tree's collection if parent is null
//or the parent node's Children otherwise)

For each item in items
If the user does not have permission to use the item then skip it
If the item is hidden then skip it
If the item is a folder
folderNode = Create a folder node and associate the folder path with it
Add the node to the parent node collection
BuildTree(folder path, folderNode)
If the item is a report
Create a report node and associate the report path with it
}

This works provided you want to populate the entire tree up front but can be slow if there are a lot of nodes. The alternative is to populate only the root level elements and then build the contents of a folder node when it is clicked. For Windows apps I'd go that route. For web apps I'd either build it all up front or use callbacks to avoid a postback. The only issue is determining whether to display the expand/collapse button next to the folder. You can either always display it by adding a dummy node that is removed when the real contents are brought over or actually check to see if the folder is empty. Again for Windows apps I'd probably just query for the correct value. In the web world I'd probably just always put the + there.

As another aside I would store the actual catalog item if this is a Windows app to avoid requerying the RS. For the web though just store the path because you'll have to requery the RS anyway on postback.

Hope this helps,

Michael Taylor - 5/12/06

TaylorMichaelL
reply 2

You can use google to search for other answers

 

More Articles

• Sending message to dialog form
• Thread | Invoke Issue
• serialport- stopbits.none error
• c# expression evaluator, Immediate window control, or interpreter
• how to write Factory Interface Handlers
• MSMQ Serialization/Deserialization
• Button with dropdown menu
• SDK for software license keys?
• TreeView adding nodes
• HTML Pagination
Bookmark and Share
Welcome to Bokebb   New Update  
 

New Articles

• Multi-threaded copy
• link label
• Does someone have the sample or document
• rtf to image
• How can i extract labels based on a cert
• Progressbar strange error
• Howto create a thumbnail from a wmv file ?
• How can I show the line number beside a
• Threading, Atomic wait and exit lock
• What is a Hashtable?
• Control Panel
• exercises in c#
• why .net programming is called attribute
• C# SQL and ASP
• C# and MS SQL 2005

Hot Articles

• .Net 2.0 Winform takes time to load cont
• How to get total memory of computer
• How to migrate business logic from oracl
• Strange BinaryFormatter Version Incompat
• How can i send SMS or make phone calls f
• Error calling fucntions of VB ActiveX ex
• proper way to close a form using toolStr
• Where is best place to declare frequentl
• Printing A HTML Page In The Web Browser
• Error: allowDefinition='MachineToApplica
• Remote connection to SQLEXPRESS
• Binding a textbox to a database field us
• Console Application & Parameter
• UserControl Terminate or Close Event
• Sharing a contextmenu

Recommend Articles

• Windows Service Won't Start Automatically
• Date
• How can I speed this up: excel spreadshe
• Index of a string within another string
• Using multiline regex's on more than one
• Chinese characters in a C# windows form
• dll
• updating dataset
• c#
• Font Dialog with color
• How can I use the delegate to update the
• .NET 2.0 WIndows Service Deployment
• using vs #include
• calender in datagridview cloumn
• Converting a float[] reference to byte[]