Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Treeview Control in .NET

Status
Not open for further replies.

zqtqzq

Programmer
Jul 23, 2003
61
A2
I have a Control file(in Access DB) from which i load treeview items (in vb6) using a Table Field called ID as the key for the treeview item.
This treeview is in tandem with a listview control(vb6) which lists subitems corresponding to the treeview Key.
I have done this fine in vb6

but with dotnet, i did not see any key to control and display treeview item and the listview item.

Pls assist in this regard
 
You can use the Tag property of a TreeNode to store a key value.
 
I will try the tag property to see how it works.
What of the listview key property. Does the listview also has a tag property?
thanks
 
Thanx using the tag to track the treeview item worked

pls what of tracking the listview items? since teh listview items does not having anything like index or key to know the particulat item selected.

I have also tried the Tag ppty with the listview but did not work
any code will be appreciated




 
Hi zqtqzq,

The listview does have a tag property. You just have to determine the item.... something like this:

Me.ListView1.FocusedItem.Tag()

pcguru.gif
 
i tried the FocusedItem property of the listview to assign an index/key to the listview items but i encountered the following error:

An unhandled exception of type 'System.NullReferenceException' occurred in AdvancedControls.exe

Additional information: Object reference not set to an instance of an object.

below is the code snippet i am using


Private Sub LoadGroupItems(ByVal mKey As Integer)
'Loads Listview with Menu Items belonging to a GroupID
Dim oDs As DataSet = New DataSet
Dim oDa As OleDbDataAdapter = New OleDbDataAdapter

Dim oCmd As OleDbCommand = New OleDbCommand
Dim dRow As DataRow
Dim GroupItem As String
Dim mParent As Integer

strSQL = "Select * From Task Where HasSubGrp=0 and parent = " & mKey & " ORDER BY ID"

Try
With oCmd
.CommandText = strSQL
.CommandType = CommandType.Text
.Connection = oCnn
End With
oDa.SelectCommand = oCmd
oDs.Clear()
oDa.Fill(oDs, "UserTB")

Dim k As Integer = 0
lstView.Items.Clear()
lstView.ArrangeIcons(ListViewAlignment.Top)
For Each dRow In oDs.Tables("UserTB").Rows
lstView.Items.Add(dRow.Item("Task"), 0)
lstView.FocusedItem.Tag = k
k = k + 1
Next

oDs.Clear()
Catch ex As ApplicationException
MsgBox(ex.Message)
End Try
End Sub

--- the error is breaking on line
lstView.FocusedItem.Tag = k
with the error

I also tried to create an instance of the listview control like this

dim mV as listview
mv=lstView

and now used mv inplace of lstView but the same error surfaced.

note: lstView is my control ID






 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top