|
-
Jun 22nd, 2004, 11:41 AM
#1
Thread Starter
Frenzied Member
*RESOLVED* get tag property from selected listview item *CODE MODIFIED SAME ERROR*
how can you get the tag property for a selected item in a listview when the SelectedIndexChanged event is fired?
thanx
Last edited by vbdotnetboy; Jun 22nd, 2004 at 01:11 PM.
-
Jun 22nd, 2004, 12:04 PM
#2
Thread Starter
Frenzied Member
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
-
Jun 22nd, 2004, 12:20 PM
#3
Thread Starter
Frenzied Member
Modified code
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
-
Jun 22nd, 2004, 12:54 PM
#4
Hyperactive Member
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
-
Jun 22nd, 2004, 01:11 PM
#5
Thread Starter
Frenzied Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|