problem repopulating a listview after sorting it


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 9 of 9

Thread: problem repopulating a listview after sorting it

  1. #1
    Join Date
    Dec 2003
    Posts
    57

    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 08:33 AM. Reason: Added Code Tags

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    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

  3. #3
    Join Date
    Dec 2003
    Posts
    57
    Thanks. I've tried that, and also added a lvCallLog.Refresh but it gets me the same thing. However, thanks again for the suggestion.

  4. #4
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    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

  5. #5
    Join Date
    Dec 2003
    Posts
    57
    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.

  6. #6
    Join Date
    Mar 2008
    Location
    Lancashire, UK
    Posts
    156
    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())

  7. #7
    Join Date
    Jan 2009
    Location
    Saint Louis, MO
    Posts
    23
    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.

  8. #8
    Join Date
    Dec 2003
    Posts
    57
    Thanks!

  9. #9
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Quote Originally Posted by Skoffer View Post
    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

  1. problem loading more array in listview
    By shamsam1 in forum VB Classic
    Replies: 6
    Last Post: 04-23-2008, 11:26 AM
  2. Sorting a ListView containing date or numeric values
    By Traci A. Butler in forum .NET
    Replies: 9
    Last Post: 03-18-2002, 11:08 PM
  3. Replies: 0
    Last Post: 02-11-2002, 03:10 PM
  4. ListView LVM_GETNEXTITEM message problem
    By John Palmer in forum VB Classic
    Replies: 0
    Last Post: 06-18-2001, 01:13 PM
  5. Listview boxes
    By Kenneth in forum VB Classic
    Replies: 0
    Last Post: 04-24-2001, 12:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center