-
problem repopulating a listview after sorting it
Hi,
This code works well in populating a listview. However, when I click on a column to sort the listview (which works fine) then run the same SQL & code to repopulate the listview, I end up with the first column getting populated but the rest of the columns do not. What am I doing wrong? Thanks!
Code:
Private Sub ShowDetail()
' this code works to populate the listview the first time but not after the listview is sorted
Dim nCount As Integer
Dim nNum As Integer
Dim sFlag As String
Dim sFromDate As String
Dim sToDate As String
Dim sDate As String
If DBGetCSCNotes(txtFromDate, txtToDate, maNOTES()) Then
If Not UBound(maNOTES) Then
For nCount = 1 To UBound(maNOTES)
With maNOTES(nCount)
sDate = Format$(.sTime, "mm/dd/yy")
lvCallLog.ListItems.Add , , LTrim(RTrim(sDate)) ' this populates & repopulates ok
' the rest of these do not
lvCallLog.ListItems(nCount).ListSubItems.Add 1, , LTrim(RTrim(.sANPACOwnerLastName)) & ", " & LTrim(RTrim(.sANPACOwnerFirstName))
lvCallLog.ListItems(nCount).ListSubItems.Add 2, , LTrim(RTrim(.sANPACAcctID))
lvCallLog.ListItems(nCount).ListSubItems.Add 3, , LTrim(RTrim(.sPolicyNumber))
lvCallLog.ListItems(nCount).ListSubItems.Add 4, , LTrim(RTrim(.sBody))
lvCallLog.ListItems(nCount).Tag = .lNoteid
End With
Next nCount
mnNumItems = nCount
End If
Else
End If
End Sub
Private Sub lvCallLog_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
' I use this to sort
Dim sString As String
sString = ColumnHeader.Text
If ColumnHeader.Text = "Date" Then
If lvCallLog.SortOrder = lvwAscending Then
lvCallLog.SortOrder = lvwDescending
Else
lvCallLog.SortOrder = lvwAscending
End If
ElseIf ColumnHeader.Text = "Client" Then
If lvCallLog.SortOrder = lvwAscending Then
lvCallLog.SortOrder = lvwDescending
Else
lvCallLog.SortOrder = lvwAscending
End If
End If
' Set Sorted to True to sort the list.
lvCallLog.Sorted = True
End Sub
Last edited by Hack; 11-20-2008 at 07:33 AM.
Reason: Added Code Tags
-
Try this
Code:
Private Sub ShowDetail()
'add this line
lvCallLog.Clear
'here is the rest of your code
End Sub
Also, I edited your thread and added [code]your code goes here[/code] as it makes reading posted code a bit easier.
I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
Please use [Code]your code goes in here[/Code] tags when posting code.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
Modifications Required For VB6 Apps To Work On Vista
-
Thanks. I've tried that, and also added a lvCallLog.Refresh but it gets me the same thing. However, thanks again for the suggestion.
-
Then put a break on your sub and step through it to see exactly what it is doing.
I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
Please use [Code]your code goes in here[/Code] tags when posting code.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
Modifications Required For VB6 Apps To Work On Vista
-
I've done that. It writes the first row correctly. After that it just fills in the first column. When I step through the code, it appears the data is going in to the columns but it just doesn't display, except for the first column. What I end up with is the first row looking like it should and every other row with just the first column filled in.
And thanks for the reminder about hpw to post the code, I'll try to remember that next time.
-
Are you sure that's the right way to add to a listview?
Try this;
Replace the code to add to the listview and its sub-thingys with this:
Code:
AddToList sDate, .sANPACOwnerLastName & ", " & .sANPACOwnerFirstName, _
.sANPACAcctID, .sPolicyNumber, .sBody, .lNoteid
Then add this function to your code somewhere
Code:
Private Sub AddToList(sDate As String, OwnerLastName As String, _
AcctID As String, sPolicyNumber As String, sBody As String, NoteID As String)
lvCallLog.ListItems.Add , , Trim$(sDate)
With lvFiles.ListItems(lvFiles.ListItems.Count)
.SubItems(1) = Trim(OwnerLastName)
.SubItems(2) = Trim(AcctID)
.SubItems(3) = Trim(sPolicyNumber)
.SubItems(4) = Trim(sBody)
.Tag = Trim(NoteID)
End With
End Sub
You might need to add columns to the listview at design-time, i can't remember exactly. Give it a go.
Also, you can use Trim() instead of LTrim(RTrim())
-
Sorry for digging up this old thread, but I was just having this same problem and found the solution.
Before you repopulate the listview, you must set .sorted to false.
Code:
lvCallLog.sorted = false
This is the correct solution to this problem.
-
-
 Originally Posted by Skoffer
Sorry for digging up this old thread
When answers are supplied, apologies are unnecessary.
I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
Please use [Code]your code goes in here[/Code] tags when posting code.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
Modifications Required For VB6 Apps To Work On Vista
Similar Threads
-
By shamsam1 in forum VB Classic
Replies: 6
Last Post: 04-23-2008, 10:26 AM
-
By Traci A. Butler in forum .NET
Replies: 9
Last Post: 03-18-2002, 10:08 PM
-
By Traci Butler in forum ASP.NET
Replies: 0
Last Post: 02-11-2002, 02:10 PM
-
By John Palmer in forum VB Classic
Replies: 0
Last Post: 06-18-2001, 12:13 PM
-
By Kenneth in forum VB Classic
Replies: 0
Last Post: 04-24-2001, 11:04 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks