Sam Stephenson
Sam Stephenson

Reputation: 5190

What variable is used to store treeview data

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()
{
}

Upvotes: 0

Views: 1507

Answers (1)

heetseekel2
heetseekel2

Reputation: 36

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

Upvotes: 1

Related Questions