none
vb.net problem with auto duplicate in listview RRS feed

  • Question

  • hello all 

    All that you press on the button doubles the number of lines if add one in second press add three 

    please i need yourss help

     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Try
                Dim i As Integer
    
                str = "SELECT * FROM food_details WHERE name = '" & Tabel1.sname & "'"
                With comm
                    .CommandText = str
                    .Connection = conn
                End With
                With dataa
                    .SelectCommand = comm
                    .Fill(datat)
                End With
                If Tabel1.ListView2.SelectedItems.Count > 0 Then
                    For i = 0 To datat.Rows.Count - 1
                        With Tabel1.ListView3
                            .Items.Add(datat.Rows(i)("name"))
                            With .Items(.Items.Count - 1).SubItems
                                .Add(datat.Rows(i)("price"))
                                .Add((NumericUpDown1.Value))
                                .Add(datat.Rows(i)("categories"))
                            End With
                        End With
                    Next
                    'MessageBox.Show(str)
                End If
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
            Me.Close()
    
        End Sub

    Friday, June 16, 2017 9:41 PM

All replies

  • Consider using a DataGridView which supports databinding - a Listview doesn't but as to why you're seeing them twice: You didn't clear the items before you added new ones:

    ListView1.Items.Clear

    Now add whatever you want.


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Friday, June 16, 2017 10:08 PM
  • hello all 

    All that you press on the button doubles the number of lines if add one in second press add three 

    please i need yourss help

     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Try
                Dim i As Integer
    
                str = "SELECT * FROM food_details WHERE name = '" & Tabel1.sname & "'"
                With comm
                    .CommandText = str
                    .Connection = conn
                End With
                With dataa
                    .SelectCommand = comm
                    .Fill(datat)
                End With
                If Tabel1.ListView2.SelectedItems.Count > 0 Then
                    For i = 0 To datat.Rows.Count - 1
                        With Tabel1.ListView3
                            .Items.Add(datat.Rows(i)("name"))
                            With .Items(.Items.Count - 1).SubItems
                                .Add(datat.Rows(i)("price"))
                                .Add((NumericUpDown1.Value))
                                .Add(datat.Rows(i)("categories"))
                            End With
                        End With
                    Next
                    'MessageBox.Show(str)
                End If
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
            Me.Close()
    
        End Sub

    Hi

    Since you onlt have 2 days, I wish you good luck (from your other thread). You maybe took on more than you can chew.

    Regards Les, Livingston, Scotland

    Friday, June 16, 2017 11:57 PM