Results 1 to 5 of 5

Thread: *RESOLVED* get tag property from selected listview item *CODE MODIFIED SAME ERROR*

  1. #1

    Thread Starter
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310

    *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.

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

  2. #2

    Thread Starter
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310
    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:
    1. Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
    2.         Try
    3.             MsgBox(Me.ListView1.SelectedItems(0).Text)
    4.             '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)
    5.         Catch ex As Exception
    6.             MsgBox(ex.Message)
    7.         End Try
    8.     End Sub

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

  3. #3

    Thread Starter
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310

    Modified code

    VB Code:
    1. Private Sub lvLibs_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lvLibs.SelectedIndexChanged
    2.         Dim lv As ListViewItem
    3.         Try
    4.             'MsgBox(Me.ListView1.SelectedItems(0).Text)
    5.             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)
    6.             adoRdr = adoCmd.ExecuteReader
    7.  
    8.             While adoRdr.Read
    9.                 lv = New ListViewItem(CStr(adoRdr("proj_name")))
    10.                 lv.Tag = adoRdr("PROJ_ID")
    11.                 Me.lvProjs.Items.Add(lv)
    12.             End While
    13.         Catch ex As Exception
    14.             MsgBox(ex.Message)
    15.         Finally
    16.             If Not IsNothing(adoRdr) Then
    17.                 adoRdr.Close()
    18.             End If
    19.             If Not IsNothing(adoCmd) Then
    20.                 adoCmd.Dispose()
    21.             End If
    22.             adoRdr = Nothing
    23.             adoCmd = Nothing
    24.         End Try
    25.     End Sub

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

  4. #4
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    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:
    1. Private Sub lvLibs_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lvLibs.SelectedIndexChanged
    2.         Dim lv As ListViewItem
    3.         Try
    4.             'MsgBox(Me.ListView1.SelectedItems(0).Text)
    5.             [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)
    6.             adoRdr = adoCmd.ExecuteReader
    7.  
    8.             While adoRdr.Read
    9.                 lv = New ListViewItem(CStr(adoRdr("proj_name")))
    10.                 lv.Tag = adoRdr("PROJ_ID")
    11.                 Me.lvProjs.Items.Add(lv)
    12.             End While
    13.         Catch ex As Exception
    14.             MsgBox(ex.Message)
    15.         Finally
    16.             If Not IsNothing(adoRdr) Then
    17.                 adoRdr.Close()
    18.             End If
    19.             If Not IsNothing(adoCmd) Then
    20.                 adoCmd.Dispose()
    21.             End If
    22.             adoRdr = Nothing
    23.             adoCmd = Nothing
    24.         End Try
    25.     End Sub

  5. #5

    Thread Starter
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310
    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.

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width