2022年7月19日 星期二

HOW TO FILL UP A LISTVIEW FROM DATABASE IN VB.NET USING A DATATABLE

 參考網址

--


Sub FillListViewByTable(ByVal listView As ListView, ByVal dt As DataTable)

        Dim ii As Integer

        Dim iColCount As Integer = dt.Columns.Count

        Dim iRowCount As Integer = dt.Rows.Count

        listView.Clear()

        For ii = 0 To iColCount – 1

            listView.Columns.Add(dt.Columns(ii).ColumnName, 250, HorizontalAlignment.Left)

          

        Next

   

        Dim i As Integer

        Dim x As Integer

        For i = 0 To iRowCount – 1  ‘ for each row in the table

            Dim lst As New ListViewItem

            lst.Text = dt.Rows(i).Item(0)

            lst.UseItemStyleForSubItems = True

            For x = 1 To iColCount – 1 ‘ for each column in the row of the table

                Application.DoEvents()

                lst.SubItems.Add(SNZ(dt.Rows(i).Item(x)))

             

            Next


               Application.DoEvents()

           ‘    If you want to display the progress then you can do it here

           ‘ myStatusLabel.text = “Displaying Record ” & i + 1 & “/” & iRowCount

            listView.Items.Add(lst)

            lst = Nothing

        Next

    

    End Sub

沒有留言:

張貼留言