Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Problem with items for listview . if can't ,say me please [modified]

Problem with items for listview . if can't ,say me please [modified]

Scheduled Pinned Locked Moved .NET (Core and Framework)
questiondatabasehelp
5 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    darkyro
    wrote on last edited by
    #1

    hi i'm creating a program with two listview. one get the "Group" and other get the "members of the selected Group" but i have problem only get the first member .

    Private Sub ListView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged

    lstestacoes.Clear()
    lstestacoes.View = View.LargeIcon
    Try
    If con.State = ConnectionState.Open Then con.Close()
    con.Open()
    Dim ind As Integer
    Dim temp As String

    For Each item As ListViewItem In ListView1.SelectedItems
    If item.Selected = True Then

    temp = item.SubItems(0).Text
    itemSelected = item.SubItems(0).Text
    Dim cmd As New OleDbCommand("select * from Estacao WHERE idGrupo= '" & temp & "'", con)

    Dim drdr As OleDbDataReader
    drdr = cmd.ExecuteReader
    If drdr.Read() Then
    ind = ind + 1
    Dim i As New ListViewItem(ind)
    i.Text = drdr.Item("Nome")
    i.ImageIndex = 0
    lstestacoes.Items.AddRange(New ListViewItem() {i})

    Else
    cmd.Cancel()
    con.Close()
    End If
    End If
    Next item

    Catch ex As Exception
    MsgBox(ex.Message)
    End Try

    End Sub

    My database have two tables "Grupo" and "Estacoes" obs : "Grupo" is the Group and "Estacoes" is the members at the group i have = id,name and in Estacoes i have = id,name,ip,descricao,grupo how can i set to get all members ? :doh:SORRY LONG TIME I'M NOT SPEAK ENGLISH:cool:

    modified on Friday, November 13, 2009 6:09 PM

    L L 2 Replies Last reply
    0
    • D darkyro

      hi i'm creating a program with two listview. one get the "Group" and other get the "members of the selected Group" but i have problem only get the first member .

      Private Sub ListView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged

      lstestacoes.Clear()
      lstestacoes.View = View.LargeIcon
      Try
      If con.State = ConnectionState.Open Then con.Close()
      con.Open()
      Dim ind As Integer
      Dim temp As String

      For Each item As ListViewItem In ListView1.SelectedItems
      If item.Selected = True Then

      temp = item.SubItems(0).Text
      itemSelected = item.SubItems(0).Text
      Dim cmd As New OleDbCommand("select * from Estacao WHERE idGrupo= '" & temp & "'", con)

      Dim drdr As OleDbDataReader
      drdr = cmd.ExecuteReader
      If drdr.Read() Then
      ind = ind + 1
      Dim i As New ListViewItem(ind)
      i.Text = drdr.Item("Nome")
      i.ImageIndex = 0
      lstestacoes.Items.AddRange(New ListViewItem() {i})

      Else
      cmd.Cancel()
      con.Close()
      End If
      End If
      Next item

      Catch ex As Exception
      MsgBox(ex.Message)
      End Try

      End Sub

      My database have two tables "Grupo" and "Estacoes" obs : "Grupo" is the Group and "Estacoes" is the members at the group i have = id,name and in Estacoes i have = id,name,ip,descricao,grupo how can i set to get all members ? :doh:SORRY LONG TIME I'M NOT SPEAK ENGLISH:cool:

      modified on Friday, November 13, 2009 6:09 PM

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, 1. please use PRE tags instead of CODE tags to make things readable. You can still edit your original message... 2. I doubt Dim i As New ListViewItem(ind) is correct. Try Dim i As New ListViewItem() :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


      D 1 Reply Last reply
      0
      • L Luc Pattyn

        Hi, 1. please use PRE tags instead of CODE tags to make things readable. You can still edit your original message... 2. I doubt Dim i As New ListViewItem(ind) is correct. Try Dim i As New ListViewItem() :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


        D Offline
        D Offline
        darkyro
        wrote on last edited by
        #3

        ok i will use. but in the data base the colunn idGrupo is "Lab1" for exemple not number. in group the items are inserted correctly but foe members no, why ? the problem is when the code are debugin only get one member "the first" is because i'm searching for string at database for example "Lab1" in colunn "idGrupo" ? i don't know why he get only the first provabily the code is wrong ^^"

        1 Reply Last reply
        0
        • D darkyro

          hi i'm creating a program with two listview. one get the "Group" and other get the "members of the selected Group" but i have problem only get the first member .

          Private Sub ListView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged

          lstestacoes.Clear()
          lstestacoes.View = View.LargeIcon
          Try
          If con.State = ConnectionState.Open Then con.Close()
          con.Open()
          Dim ind As Integer
          Dim temp As String

          For Each item As ListViewItem In ListView1.SelectedItems
          If item.Selected = True Then

          temp = item.SubItems(0).Text
          itemSelected = item.SubItems(0).Text
          Dim cmd As New OleDbCommand("select * from Estacao WHERE idGrupo= '" & temp & "'", con)

          Dim drdr As OleDbDataReader
          drdr = cmd.ExecuteReader
          If drdr.Read() Then
          ind = ind + 1
          Dim i As New ListViewItem(ind)
          i.Text = drdr.Item("Nome")
          i.ImageIndex = 0
          lstestacoes.Items.AddRange(New ListViewItem() {i})

          Else
          cmd.Cancel()
          con.Close()
          End If
          End If
          Next item

          Catch ex As Exception
          MsgBox(ex.Message)
          End Try

          End Sub

          My database have two tables "Grupo" and "Estacoes" obs : "Grupo" is the Group and "Estacoes" is the members at the group i have = id,name and in Estacoes i have = id,name,ip,descricao,grupo how can i set to get all members ? :doh:SORRY LONG TIME I'M NOT SPEAK ENGLISH:cool:

          modified on Friday, November 13, 2009 6:09 PM

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          I think this line is the culprit

          If item.Selected = True Then

          Remove this If condition and try again.

          D 1 Reply Last reply
          0
          • L Lost User

            I think this line is the culprit

            If item.Selected = True Then

            Remove this If condition and try again.

            D Offline
            D Offline
            darkyro
            wrote on last edited by
            #5

            i'm used other code to resolve this problem . i'll post where for know how code i used.

            Private Sub ListView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged

                lstestacoes.Clear()
                lstestacoes.View = View.LargeIcon
                Try
                    If con.State = ConnectionState.Open Then con.Close()
                    lstestacoes.Clear()
                    lstestacoes.View = View.LargeIcon
                    Dim ind As Integer
                    Dim temp As String
                    
                    For Each item As ListViewItem In ListView1.SelectedItems
                        If item.Selected = True Then
                            temp = item.SubItems(0).Text
                            Dim adptr As New OleDbDataAdapter("select \* from Estacao WHERE Grupo= '" & temp & "'", con)
                            Dim ds As New DataSet
                            Dim dr As DataRow
                            Dim dt As New DataTable
                            Dim imageListSmall As New ImageList()
                            Dim imageListLarge As New ImageList()
            
                            Dim grupoquant As Integer
                            Try
                                adptr.Fill(ds, "Grupo")
                                dt = ds.Tables(0)
                               
                                For Each dr In dt.Rows
                                   
                                  
                            
                                    ind = ind + 1
                                    Dim i As New ListViewItem(ind)
                                    i.Text = dr.Item("Nome")
                                    i.ImageIndex = 0
                                   
                                    lstestacoes.Items.AddRange(New ListViewItem() {i})
                     
                                Next
            
                            Catch ex As Exception
                    MsgBox(ex.Message)
            
                End Try
                        End If
                    Next
                Catch ex As Exception
                    MsgBox(ex.Message)
            
                End Try
            
            
                con.Close()
            

            end sub

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups