Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listview columns question

Status
Not open for further replies.

dbrew0

Technical User
Dec 15, 2003
38
US
I have a listview which I have entered 10 columns in the design view. I populate this listview from a database using a datareader to a datatable. When I populate the listview, my manually created column headers disappear and are replaced with the column headers from the columns in the database. If I skip the code where the columns from the database are written to the columns of the listview, the listview columns still disappear, and I don't get any data populated. The question is why? It doesn't make sense to allow me to manually create the columns only to overwrite them later. I have also noticed that the Listview1.Columns.Count is 0 before the datatable columns are written to the listview. If I created the columns manually shouldn't the .count show that many columns in the collection?

Below is a snippet of the code where the datatable columns are written to the listtable columns.

Code:
      If ListView1.Columns.Count < tblHoursData.Columns.Count Then

        'iterate through each column in the columns collection for the table.  then set the listview column header names=the column names
        Dim tblColumn As DataColumn
        For Each tblColumn In tblHoursData.Columns
          ListView1.Columns.Add(tblColumn.ColumnName)
        Next
      ElseIf ListView1.Columns.Count > tblHoursData.Columns.Count Then

      End If

Thanks
Dan
 
Sorry everyone...I didn't see that a ListView1.Clear statement had been put in far above the code I was having problems with. That's what I get for putting this aside for months then picking it back up.

All is good now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top