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.
Thanks
Dan
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