lifeson
03-04-2008, 01:05 AM
I am experiencing a bug with a list view control that is driving me nuts :bug:
I use this bit of code to populate the listview and it works fine
Private Sub CheckQty()
Dim x As Long, i As Long
Dim chkRow As Long
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("BlrCopy")
chkRow = ws.Cells(Rows.Count, "A").End(xlUp).row - 1
Application.ScreenUpdating = False
If chkRow >= 1 Then
x = 1
With lvwBoilers
.ListItems.Clear
For i = 2 To chkRow + 1 'set range to search
.ListItems.Add , , ws.Cells(i, "A").Value
.ListItems(x).ListSubItems.Add , , ws.Cells(i, "B").Value
.ListItems(x).ListSubItems.Add , , ws.Cells(i, "C").Value
.ListItems(x).ListSubItems.Add , , ws.Cells(i, "D").Value
.ListItems(x).ListSubItems.Add , , ws.Cells(i, "E").Value
.ListItems(x).ListSubItems.Add , , ws.Cells(i, "F").Value
x = x + 1
Next I
End With
TextBox1.Value = chkRow & " items match the criteria"
Else
lvwBoilers.ListItems.Clear
TextBox1.Value = chkRow & " items match the criteria, try alternative inputs"
End If
End Sub[/vba]
I use this bit of code to allow the listview to be sorted when the columnheaders are clicked and it also works fine.
[Code]Private Sub lvwBoilers_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
With lvwBoilers
Static iLast As Integer, iCur As Integer
.Sorted = True
iCur = ColumnHeader.Index - 1
If iCur = iLast Then .SortOrder = IIf(.SortOrder = 1, 0, 1)
.SortKey = iCur
iLast = iCur
End With
End Sub
However, after the code has run to sort the columns, the code to poulate the list box doesn't work correctly.
It fills the first column of the list box but all other columns are empty except that last row.
Does anything look obviously wrong?
I use this bit of code to populate the listview and it works fine
Private Sub CheckQty()
Dim x As Long, i As Long
Dim chkRow As Long
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("BlrCopy")
chkRow = ws.Cells(Rows.Count, "A").End(xlUp).row - 1
Application.ScreenUpdating = False
If chkRow >= 1 Then
x = 1
With lvwBoilers
.ListItems.Clear
For i = 2 To chkRow + 1 'set range to search
.ListItems.Add , , ws.Cells(i, "A").Value
.ListItems(x).ListSubItems.Add , , ws.Cells(i, "B").Value
.ListItems(x).ListSubItems.Add , , ws.Cells(i, "C").Value
.ListItems(x).ListSubItems.Add , , ws.Cells(i, "D").Value
.ListItems(x).ListSubItems.Add , , ws.Cells(i, "E").Value
.ListItems(x).ListSubItems.Add , , ws.Cells(i, "F").Value
x = x + 1
Next I
End With
TextBox1.Value = chkRow & " items match the criteria"
Else
lvwBoilers.ListItems.Clear
TextBox1.Value = chkRow & " items match the criteria, try alternative inputs"
End If
End Sub[/vba]
I use this bit of code to allow the listview to be sorted when the columnheaders are clicked and it also works fine.
[Code]Private Sub lvwBoilers_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
With lvwBoilers
Static iLast As Integer, iCur As Integer
.Sorted = True
iCur = ColumnHeader.Index - 1
If iCur = iLast Then .SortOrder = IIf(.SortOrder = 1, 0, 1)
.SortKey = iCur
iLast = iCur
End With
End Sub
However, after the code has run to sort the columns, the code to poulate the list box doesn't work correctly.
It fills the first column of the list box but all other columns are empty except that last row.
Does anything look obviously wrong?