0

I am looking to create the data for a treeview in a dll. I then what to use that data to form a treeview in a UI.

However I cannot figure out how to store this information in a variable i.e. string int double obivously it is neither of these but I can't see how I could use a array or hash table to do this either.

Basically I do not know of any data type capable of storing the data to use for a TreeView and was wondering if someone could let me know. If it helps I'm using C#

What do I use as the return variable?

public static SomeVariable treedata()
{
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Sam Stephenson
  • 5,200
  • 5
  • 27
  • 44

1 Answers1

1

You can use a treeview control itself to store all the data ... There are a couple of ways of storing the data, but I would create an object of type "TreeView" itself ... Once created, you can access the nodes of the object and get the data that you are looking for (See example below in VB)

Dim treeview As New TreeView
treeview.Nodes(0).Text = "Parent Node"
treeview.Nodes(0).Nodes.Add("Child Node")
Dim tempstring As String = treeview.SelectedNode.Text

If you want to do something else with the data (Like store it in as an object, process it later,etc. you can also save it to a text file and read that file later). It will depend on whether you need to store the data or not. You can store the values in a hash table as well. In order to do that, you will need to iterate through all the nodes using multiple for loops and within those loops, iterate through the columns of a hashtable while inserting values along with the node name and its parent node into the table field. If you are new to treeview, i suggest you read up on some of it ... It is not very difficult once you get how it works ... (That is, if you are indeed new to it)

Some links below to these: Saving content of a treeview to a file and load it later

Accessing all the nodes in TreeView Control

tree view bindings to a data table

Regards, Sunny

Community
  • 1
  • 1
  • Thanks sunny however Treeveiw is a object of System.Windows.Forms a dll that is not by default referanced by a dll. I was looking avoid putting a windows form object inside a dll. Be seeing that it is not displaying a UI and I want to keep the data in memory and not write a lot of while loops inside the UI I may not have a choise :( – Sam Stephenson Oct 01 '12 at 10:03
  • 1
    If I understand this correctly, below is the scneraio you are dealing with: you receive some data from the user, you use your dll to execute methods and you want to display the processed data in a treeview on the UI? How this data has been captured may be irrelevant (Seems my answer may not be your only option ...) If you already have the data (in a hash table, or in a text file, etc.), you can create the treeview at runtime from any of the above sources on the winform / aspx page ... you need not include the treeview control in the dll ... unless I have misunderstood the problem :( – heetseekel2 Oct 01 '12 at 12:08
  • I am trying to get the directory of a drive to show in treeview on a ui. The reason I am looking to do this in a dll is that the treevew will change based on which group the user that is runing the program belows to. – Sam Stephenson Oct 01 '12 at 13:28
  • Apologies for not replying sooner ... I would suggest you unmark this as answer so that other users can still try to answer your question ... This is common functionality and I'm sure there's a way of doing this ... – heetseekel2 Oct 08 '12 at 09:08