I'm a bit confused about how to best unbox the string from the treenode.tag object.
First off, there is no boxing or unboxing involved here. Since String
is a class, an Object
variable can directly hold a reference to a String
without boxing. Boxing occurs when you store a value type (Structure
) within an Object
variable.
That being said - to extract the value, since you know you're always storing a String
, you can use DirectCast
to pull out the value:
For Each tn As TreeNode In TreeView1.Nodes
Dim tag = DirectCast(tn.Tag, String)
If Not String.IsNullOrWhiteSpace(tag) Then
Call DoTagStringStuff(tag)
End If
Next tn
If other types could potentially be stored in the Tag
, or if Tag
may be left empty, then other conversions may be appropriate.