473,383 Members | 1,853 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,383 software developers and data experts.

ID Column in Treeview

Ben
Hi

We are using the treeview control unbound.

We are populating it from a database but would like to add a hidden
reference/ID column. Is this possible?

Thanks
B
Feb 15 '07 #1
5 2118
Ben wrote:
Hi

We are using the treeview control unbound.

We are populating it from a database but would like to add a hidden
reference/ID column. Is this possible?

Thanks
B

You can use the Tag property to store data.
Feb 15 '07 #2
You could use the Handle property.

T

Ben wrote:
Hi

We are using the treeview control unbound.

We are populating it from a database but would like to add a hidden
reference/ID column. Is this possible?

Thanks
B
Feb 15 '07 #3
"tomb" <to**@technetcenter.comschrieb:
You could use the Handle property.
I assume you are referring to the 'TreeNode' objects' 'Tag' property.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Feb 16 '07 #4
Ben wrote:
We are populating it from a database but would like to add a hidden
reference/ID column. Is this possible?
Yes, you can, but personally, I don't do it that way any more.

The VB6 TreeView used to have a Key property on every Node.
We used this to "lookup" the "record" (or whatever) that held data about
this particular item.
So, you started with a Node, got it's Key, then went off to /another/
data store to get the data.

Here's an alternative.

Hold each data "record" in a Class that derives from TreeNode.
Instantiate these and add them, directly, into the TreeView.

Or:

Hold each "record" in a class from which you can /obtain/ (i.e. has a
Property that returns) an object that derives from TreeNode and has a
Property "pointing back" to the "record" object).

Now, there's no need to go looking in other data stores - all the data
about whatever it is is encapsulated within that class.

Class CustomTreeNode
Inherits TreeNode

Private Sub New()
End Sub

Public Sub New( id as ... )
MyBase.New()
m_sId = id
End Sub

Public Property ID() As String
Get
Return m_sId
End Get
End Property

Private m_sId As String

End Class

....then...

For Each dr as DataRow In dtThings
Dim oNode as New CustomTreeNode( dr.Item( "ID" ).ToString() )
tvTree.Nodes.Add( oNode )
Next

Private Sub tvTree_AfterSelect( ... ) _
Handles tvTree.AfterSelect

If TypeOf e.Node Is CustomTreeNode Then
' Handle one of your custom nodes
Else
' Deal with an ordinary one
End If

End Sub

HTH,
Phill W.
Feb 16 '07 #5
Ben
Thank you all for your input

I have used the Tag, but will look into the class for future usage.

Many thanks
B

"Phill W." <p-.-a-.-w-a-r-d-@-o-p-e-n-.-a-c-.-u-kwrote in message
news:er**********@south.jnrs.ja.net...
Ben wrote:
>We are populating it from a database but would like to add a hidden
reference/ID column. Is this possible?

Yes, you can, but personally, I don't do it that way any more.

The VB6 TreeView used to have a Key property on every Node.
We used this to "lookup" the "record" (or whatever) that held data about
this particular item.
So, you started with a Node, got it's Key, then went off to /another/ data
store to get the data.

Here's an alternative.

Hold each data "record" in a Class that derives from TreeNode.
Instantiate these and add them, directly, into the TreeView.

Or:

Hold each "record" in a class from which you can /obtain/ (i.e. has a
Property that returns) an object that derives from TreeNode and has a
Property "pointing back" to the "record" object).

Now, there's no need to go looking in other data stores - all the data
about whatever it is is encapsulated within that class.

Class CustomTreeNode
Inherits TreeNode

Private Sub New()
End Sub

Public Sub New( id as ... )
MyBase.New()
m_sId = id
End Sub

Public Property ID() As String
Get
Return m_sId
End Get
End Property

Private m_sId As String

End Class

...then...

For Each dr as DataRow In dtThings
Dim oNode as New CustomTreeNode( dr.Item( "ID" ).ToString() )
tvTree.Nodes.Add( oNode )
Next

Private Sub tvTree_AfterSelect( ... ) _
Handles tvTree.AfterSelect

If TypeOf e.Node Is CustomTreeNode Then
' Handle one of your custom nodes
Else
' Deal with an ordinary one
End If

End Sub

HTH,
Phill W.

Feb 16 '07 #6

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

Similar topics

0
by: Hakimi | last post by:
How can drag and drop nodes feature be imparted to a treeview control ? How can we have a multi-column treeview?
42
by: lauren quantrell | last post by:
So many postings on not to use the treeview control, but nothing recently. Is it safe to swim there yet with Access 2000-Access 2003?
3
by: Danny Tuppeny | last post by:
Hi all, I need to build a Treeview/Listview control (none of those on codeproject do quite what I need!), and was considering using one of the existing controls as a starting point, though now...
6
by: L.M | last post by:
Hello, I knew how to use the treeview under VB6. After migrating to .NET, well, I'm lost. I try to add a new node, either to the same level or as a child to a selected node in the treeview....
14
by: Mr.D | last post by:
How do I save/load the contents of a Treeview to a file? I have found several good examples written i VB6, but not a single one for VB.NET. Please help. ---- Tim
2
by: Maileen | last post by:
Hi, I would like to draw some icon/bitmap within column header of my Treeview control. How can i do it ? thx, Maileen
3
by: barbara_dave | last post by:
Hi all, I like to dispaly treeview node text with several columns as window explorer does and put buttons on the top. When I click a button, the nodes text can be sorted by date, file size,...
8
by: Matt MacDonald | last post by:
Hi All, I have a form that displays hierarchical categories in a treeview. Ok so far so good. What I was to do is have users be able to select a node in the treeview as part of filling out the...
7
by: moondaddy | last post by:
I have WPF window and a grid. The grid has several columns and rows. How do I add an object to a specific row and column of the gird using c#? If I use: myGrid.Children.Add(dg); then dg...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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?

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.