hello everyone , i am trying to resort clv items using the following method
firts i created a List and added it to CLV then i resort some items in that list and at last i remove the sorted item from clv and insert it again at its new position . all works well , until i do sort multiable items then the clv start to repeat the items.
obviously i am doing it wrong
here is what i did
when clv have about 100 items the reinserted items gets duplicated like inserted twice , what is the correct way to sort in this case ?
firts i created a List and added it to CLV then i resort some items in that list and at last i remove the sorted item from clv and insert it again at its new position . all works well , until i do sort multiable items then the clv start to repeat the items.
obviously i am doing it wrong
here is what i did
B4X:
Public Sub SORTCLVITEM(nametofind As String)
Dim namenum() As String = Regex.Split("\~", nametofind)
Dim itemtosort1 As String
Dim itemtosort2 As String
'remove item from clv based on parameter number and adjusting its sorting
For i = 0 To Persons.Size - 1
Dim usr As Person
usr = Persons.Get(i)
If usr.userid = namenum(2) Then
usr.sortnumber = 1
usrlist.RemoveAt(i)
Exit
End If
Next
'remove and sort other item based on media1 that equal to yes
For g = 0 To Persons.Size - 1
Dim usr As Person
usr = Persons.Get(g)
If usr.media1 = "YES" Then
usr.sortnumber = 2
usr.media1 = "NO"
itemtosort1 = usr.userid ' i just added this variabl to insert later at its order
usrlist.RemoveAt(g)
Exit
End If
Next
'remove and sort other item based on media2 that equal to yes
For u = 0 To Persons.Size - 1
Dim usr As Person
usr = Persons.Get(u)
If usr.media2 = "YES" Then
usr.sortnumber = 3
usr.media2 = "NO"
itemtosort2 = usr.userid ' i just added this variable to insert it later at its order
usrlist.RemoveAt(u)
Exit
End If
Next
Persons.SortType("sortnumber", True) ' here start to sort
' start inserting the removed items based on parameter and variable to resort
For k = 0 To Persons.Size - 1
Dim usr As Person
Dim itmheigh As Int
usr = Persons.Get(k)
If usr.userid = namenum(2) Then ' parameter item to add
usrlist.InsertAt(k, Createuserafterclearlist(usr.cusername, usrlist.AsView.Width, 60dip), usr.cusername)
End If
If usr.userid = itemtosort1 Then ' sorted item1 to add
usrlist.InsertAt(k, Createuserafterclearlist(usr.cusername, usrlist.AsView.Width, 60dip), usr.cusername)
End If
If usr.userid = itemtosort2 Then 'sorted item2 to add
usrlist.InsertAt(k, Createuserafterclearlist(usr.cusername, usrlist.AsView.Width, 60dip), usr.cusername)
End If
Next
End Sub
when clv have about 100 items the reinserted items gets duplicated like inserted twice , what is the correct way to sort in this case ?