Results 1 to 8 of 8

Thread: ListView Control - Sorting Problem

Threaded View

  1. #4
    New Member
    Join Date
    Mar 2002
    Posts
    13
    hi bxn!

    you have to load all your elements in the listview control in an array. the array has .sort method, use it. afterwards fill the listview again. i will show you a peace of my code, maybe there is a shorter way to solve it but i am still learning


    Public Sub sortColumn()

    Dim i As Integer
    Dim max As Integer
    Dim ArrayInd As Integer
    Dim runvar As Integer

    For i = 0 To AxListView1.ListItems.Count - 1
    max = i
    Next

    max = max + 1
    Dim myArray As Array = Array.CreateInstance(GetType(String), max)
    Dim myArray2 As Array = Array.CreateInstance(GetType(String), max)
    Dim myArray3 As Array = Array.CreateInstance(GetType(String), max)
    Dim myArray1 As Array = Array.CreateInstance(GetType(String), max)

    For runvar = 0 To AxListView1.ListItems.Count - 1
    myArray.SetValue(AxListView1.ListItems(runvar + 1).SubItems(2), runvar)
    myArray1.SetValue(AxListView1.ListItems(runvar + 1).SubItems(2), runvar)
    myArray2.SetValue(AxListView1.ListItems(runvar + 1).Text, runvar)
    myArray3.SetValue(AxListView1.ListItems(runvar + 1).SubItems(1), runvar)
    Next
    ' Array.Sort(myArray)
    Array.Sort(myArray, myArray2, 0, max)
    For runvar = 0 To AxListView1.ListItems.Count - 1
    AxListView1.ListItems(runvar + 1).SubItems(1) = myArray(runvar)
    AxListView1.ListItems(runvar + 1).Text = myArray2(runvar)
    Next
    Array.Sort(myArray1, myArray3, 0, max)
    For runvar = 0 To AxListView1.ListItems.Count - 1
    AxListView1.ListItems(runvar + 1).SubItems(2) = myArray1(runvar)
    AxListView1.ListItems(runvar + 1).SubItems(1) = myArray3(runvar)
    Next

    End Sub

    P.S: i am using an AcitveX control with 3 columns
    Last edited by PJ6; Mar 6th, 2002 at 03:44 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
  •  



Click Here to Expand Forum to Full Width