Hello
I'm working on a project which involves userforms and listviews.
I use a hidden sheet to get a customer's data (date, shopping date etc). The data is fetched as soon as a customerID is put into cell BN41 with an advanced filter. That works OK.
The problem is populating the listview with that data and sorting it. Sometime it works, sometimes it doesn't.
When it doesn't, it messes up all the data in that control and displays blank rows as well as the (correct) data.
I have attached a screenshot to this message.
This is how I populate the listview:
And this is how I sort it:
I would be very greatful for your help as I have several listviews that need to be filled from this hidden worksheet. I got the code from a website or book - I cannot remember from which source.
I understand that the listview has an index, which in my case is the number 4. Could that be the problem? I do not exactly know what those indexes are. Could anyone explain to me what they are and used?
Thank you so much in advance for your help.
Maria
PS: I have asked thie same question to this forum. That message includes an example of my spreadsheet. I hope that it is OK to ask the same message on another forum, too.
http://www.ozgrid.com/forum/showthread.php?t=167829&p=619314#post619314
I'm working on a project which involves userforms and listviews.
I use a hidden sheet to get a customer's data (date, shopping date etc). The data is fetched as soon as a customerID is put into cell BN41 with an advanced filter. That works OK.
The problem is populating the listview with that data and sorting it. Sometime it works, sometimes it doesn't.
When it doesn't, it messes up all the data in that control and displays blank rows as well as the (correct) data.
I have attached a screenshot to this message.

This is how I populate the listview:
Code:
Public Sub ListviewAufträge()
Dim RowNumber As Long
Dim MaxRow As Long
With UserForm1.lvwAufträge
.ListItems.Clear
.ColumnHeaders.Clear
.Gridlines = True
.CheckBoxes = False
.FullRowSelect = True
.View = lvwReport
With .ColumnHeaders
.Add , , "ID", 1
.Add , , "Datum", 100
.Add , , "Zeit", 50
.Add , , "Geschäft", 80
.Add , , "Taschen", 40
.Add , , "Betrag", 40
.Add , , "Kurier", 80
End With
MaxRow = Tabelle1.Cells(Tabelle1.Rows.Count, 66).End(xlUp).Row
For RowNumber = 5 To MaxRow
.ListItems.Add , , Tabelle1.Cells(RowNumber, 66).Value
.ListItems(RowNumber - 4).ListSubItems.Add , , Tabelle1.Cells(RowNumber, 67).Text
.ListItems(RowNumber - 4).ListSubItems.Add , , Tabelle1.Cells(RowNumber, 68).Text
.ListItems(RowNumber - 4).ListSubItems.Add , , Tabelle1.Cells(RowNumber, 69).Text
.ListItems(RowNumber - 4).ListSubItems.Add , , Tabelle1.Cells(RowNumber, 70).Text
.ListItems(RowNumber - 4).ListSubItems.Add , , Tabelle1.Cells(RowNumber, 71).Text
.ListItems(RowNumber - 4).ListSubItems.Add , , Tabelle1.Cells(RowNumber, 72).Text
Next RowNumber
End With
End Sub
And this is how I sort it:
Code:
Private Sub lvwAufträge_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)With lvwAufträge
.SortOrder = IIf(.SortOrder = lvwAscending, lvwDescending, lvwAscending)
.SortKey = ColumnHeader.Index - 1
.Sorted = True
End With
End Sub
I would be very greatful for your help as I have several listviews that need to be filled from this hidden worksheet. I got the code from a website or book - I cannot remember from which source.
I understand that the listview has an index, which in my case is the number 4. Could that be the problem? I do not exactly know what those indexes are. Could anyone explain to me what they are and used?
Thank you so much in advance for your help.
Maria
PS: I have asked thie same question to this forum. That message includes an example of my spreadsheet. I hope that it is OK to ask the same message on another forum, too.
http://www.ozgrid.com/forum/showthread.php?t=167829&p=619314#post619314
Last edited: