Click here to Skip to main content
15,891,597 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.

I do get this error: A first chance exception of type 'System.ArgumentException' occurred in Microsoft.VisualBasic.dll

VB
    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
Posted
Updated 16-Jul-10 6:32am
v3

Hi,

in "SetColumnHeaders(..)" you create the columns for your listviews.
That only works for the first listview, as you set the ColumnsSet
class variable to true while filling the first one. Then, when
filling the second one, this variable is already set to true and you
dont do it again for the second listview.

So, your listview may have data (you see scrollbars), but it has no columns.

And what about that exception? Where is it thrown, what is null?
 
Share this answer
 
Comments
cuchulainn18 16-Jul-10 14:20pm    
Reason for my vote of 5
Spot on with the problem.
cuchulainn18 16-Aug-10 10:42am    
Reason for my vote of 5
This was spot on.
Thank you so much!!! My learning continues.

~Jack
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900