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