none
How to show particular data (display member) in listview... RRS feed

  • Question

  • Hello

    I create a project in vb.net 2010 with access database. I want to show data in listview. It Is show in listview but a problem I entry Id wise. So, when I click on the show data button I see the Id . How to show the id wise actual data.

    I use the code for data load in listview1

    https://ibb.co/dMxxua
    https://ibb.co/fHTgLF
    https://ibb.co/b4bCSv
    https://ibb.co/eRmqEa

    What I have tried:


    Public Sub Displayitem()
            ListView1.Items.Clear()
            Dim cmd As New OleDb.OleDbCommand("SELECT * FROM pur_inv ORDER BY purinvdt", cn)
            Dim dr As OleDb.OleDbDataReader = cmd.ExecuteReader()
            Do While dr.Read()
                Dim new_item As New  _
         ListViewItem(dr.Item("purinvdt").ToString)
                new_item.SubItems.Add(dr.Item("purinvid").ToString)
                new_item.SubItems.Add(dr.Item("prtid").ToString)
                new_item.SubItems.Add(dr.Item("invtypid").ToString)
                new_item.SubItems.Add(dr.Item("taxamt").ToString)
                new_item.SubItems.Add(dr.Item("tottaxblamt").ToString)
                new_item.SubItems.Add(dr.Item("invamt").ToString)
                ListView1.Items.Add(new_item)
            Loop
        End Sub

    Friday, July 7, 2017 1:24 PM

Answers

  •  It Is show in listview but a problem I entry Id wise. So, when I click on the show data button I see the Id . How to show the id wise actual data.

    Hi Jayanta,

    According to your description, you want to retrieve data from Access DataBase into ListView, I'm right? If yes, please refer to:

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
            Dim strConn As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Database\Database1.accdb; Persist Security Info=False;"
            Using conn As New OleDbConnection(strConn)
                Dim selectSql = "select * from Test2"
                Using com As New OleDbCommand(selectSql, conn)
                    Try
                        conn.Open()
                        Dim reader As OleDbDataReader = com.ExecuteReader()
                        If reader.HasRows() Then
    
                            While reader.Read()
                                Dim newitem As New ListViewItem()
                                newitem.Text = reader.GetValue(0) 'first column
                                newitem.SubItems.Add(reader.GetValue(1)) 'second column
                                newitem.SubItems.Add(reader.GetValue(2))
                                newitem.SubItems.Add(reader.GetValue(3))
                                ListView1.Items.Add(newitem)
                            End While
                        End If
                        conn.Close()
                    Catch ex As Exception
                        MessageBox.Show(ex.ToString())
                    End Try
                End Using
            End Using
        End Sub
        Private Sub Form13_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            ListView1.Columns.Add("ID", 50, HorizontalAlignment.Left)
            ListView1.Columns.Add("Column1", 100, HorizontalAlignment.Left)
            ListView1.Columns.Add("Column2", 100, HorizontalAlignment.Left)
            ListView1.Columns.Add("Column3", 100, HorizontalAlignment.Left)
            'Display listview in details view
            ListView1.View = View.Details
            'display grid lines
            ListView1.GridLines = True
            'allow full row selection
            ListView1.FullRowSelect = True
        End Sub

    If not, please explain this sentence “  It Is show in listview but a problem I entry Id wise. So, when I click on the show data button I see the Id . How to show the id wise actual data.”

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Jayanta Modak Monday, July 10, 2017 6:15 AM
    Monday, July 10, 2017 6:04 AM
    Moderator