how can you get the tag property for a selected item in a listview when the SelectedIndexChanged event is fired?
thanx
how can you get the tag property for a selected item in a listview when the SelectedIndexChanged event is fired?
thanx
i forgot to mention that i keep getting this error: Specified argument was out of the range of valid values.
here is my code...this is just debug code until i get it working:
VB Code:
Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged Try MsgBox(Me.ListView1.SelectedItems(0).Text) 'adoCmd = New OleDbCommand("SELECT PROJ_ID proj_name FROM [Library Information] INNER JOIN lib_proj_tbl ON [Library Information].ID = lib_proj_tbl.LIB_ID WHERE [Library Information].ID = ", adoCnn) Catch ex As Exception MsgBox(ex.Message) End Try End Sub
VB Code:
Private Sub lvLibs_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lvLibs.SelectedIndexChanged Dim lv As ListViewItem Try 'MsgBox(Me.ListView1.SelectedItems(0).Text) adoCmd = New OleDbCommand("SELECT PROJ_ID, proj_name FROM [Library Information] INNER JOIN lib_proj_tbl ON [Library Information].ID = lib_proj_tbl.LIB_ID WHERE [Library Information].ID = " & CLng(Me.lvLibs.SelectedItems(0).Tag), adoCnn) adoRdr = adoCmd.ExecuteReader While adoRdr.Read lv = New ListViewItem(CStr(adoRdr("proj_name"))) lv.Tag = adoRdr("PROJ_ID") Me.lvProjs.Items.Add(lv) End While Catch ex As Exception MsgBox(ex.Message) Finally If Not IsNothing(adoRdr) Then adoRdr.Close() End If If Not IsNothing(adoCmd) Then adoCmd.Dispose() End If adoRdr = Nothing adoCmd = Nothing End Try End Sub
Interesting, no matter how I attempted to access the SelectedItems collection, on the second attempt, I received the same error. What I did to get around it is:
VB Code:
Private Sub lvLibs_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lvLibs.SelectedIndexChanged Dim lv As ListViewItem Try 'MsgBox(Me.ListView1.SelectedItems(0).Text) [COLOR=red] If Me.lvLibs.SelectedItems.Count > 0[/COLOR] Then adoCmd = New OleDbCommand("SELECT PROJ_ID, proj_name FROM [Library Information] INNER JOIN lib_proj_tbl ON [Library Information].ID = lib_proj_tbl.LIB_ID WHERE [Library Information].ID = " & CLng(Me.lvLibs.SelectedItems(0).Tag), adoCnn) adoRdr = adoCmd.ExecuteReader While adoRdr.Read lv = New ListViewItem(CStr(adoRdr("proj_name"))) lv.Tag = adoRdr("PROJ_ID") Me.lvProjs.Items.Add(lv) End While Catch ex As Exception MsgBox(ex.Message) Finally If Not IsNothing(adoRdr) Then adoRdr.Close() End If If Not IsNothing(adoCmd) Then adoCmd.Dispose() End If adoRdr = Nothing adoCmd = Nothing End Try End Sub
thanx CyberHawke...kinda odd that it has to be done that was...kinda odd that the event has to fire twice...i mean maybe it makes sense...either what...whatever...at least it works now with out the error....thanx again.:wave: