Jack Anderson

Jack Anderson

  • NA
  • 3
  • 2.8k

Second Listview doesn't show any information (But it has a scrollbar)

Jul 16 2010 10:01 AM
Hi Everyone,

I am having trouble with a tabbed windows form that is supposed to display different information under two tabs.  The code populates the first listview fine but the second one only shows a scroll bar.  Here is my code so far.  Thank you anyone who helps this greenhorn.

    Dim sCompanyID As String
    Dim sNameID As String

    Private ColumnsSet As Boolean = False
    Private Const ConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=S:\Tracker\Tracker_Tables.mdb"
    Private cn As OleDbConnection = New OleDbConnection(ConnString)

    Private Sub frmCompanyProfile_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.CompanyTypesTableAdapter.Fill(Me.Tracker_TablesDataSet.CompanyTypes)
        Call FillForm()
        Call lvEmployeesFill()
        Call lvSalesFill()
    End Sub

    Private Sub lvEmployeesFill()

        Dim cmd As OleDbCommand
        cmd = New OleDbCommand("SELECT [NameID], [First], [Last] FROM [CustomerNames] WHERE [CompanyID]=" & sCompanyID, cn)
        Filllistview(lvEmployees, cmd)
    End Sub

    Private Sub lvSalesFill()

        Dim cmd As OleDbCommand
        cmd = New OleDbCommand("SELECT [CompanyID] FROM [Sales] WHERE [CompanyID]=" & sCompanyID, cn)
        Filllistview(LVSales, cmd)
    End Sub

Private Sub Filllistview(ByVal objListView As ListView, ByRef cmd As OleDbCommand)

        cn.Open()
        Dim RowList As ArrayList = New ArrayList()
        Dim reader As OleDbDataReader = cmd.ExecuteReader()
        Do While Reader.Read()
            Dim Values(Reader.FieldCount) As Object
            Reader.GetValues(Values)
            RowList.Add(Values)
        Loop

        If Not ColumnsSet Then
            Dim schema As DataTable = Reader.GetSchemaTable()
            SetColumnHeaders(objListView, schema)
        End If
        Reader.Close()
        cn.Close()

        PopulateList(objListView, RowList)
    End Sub

    Private Sub SetColumnHeaders(ByVal objListView As ListView, ByVal schema As DataTable)
        Dim row As DataRow

        objListView.View = View.Details
        For Each row In schema.Rows
            objListView.Columns.Add(row("ColumnName"), 100, HorizontalAlignment.Left)
        Next
        ColumnsSet = True
    End Sub

    Private Sub PopulateList(ByVal objListView As ListView, ByVal RowList As ArrayList)
        objListView.Items.Clear()

        Dim row As Object()
        For Each row In RowList
            Dim OrderDetails(row.Length) As String
            'Dim col As Object
            Dim ColIdx As Integer

            For ColIdx = 0 To row.Length - 1
                OrderDetails(ColIdx) = Convert.ToString(row(ColIdx))
            Next

            Dim NewItem As ListViewItem = New ListViewItem(OrderDetails)
            objListView.Items.Add(NewItem)
        Next
    End Sub