TRI D'UN OBJET GRID À PARTIR D'UNE COLONE RÉFÉRENTE

tdihedi Messages postés 3 Date d'inscription mardi 6 avril 2004 Statut Membre Dernière intervention 4 mai 2004 - 4 mai 2004 à 14:24
tdihedi Messages postés 3 Date d'inscription mardi 6 avril 2004 Statut Membre Dernière intervention 4 mai 2004 - 4 mai 2004 à 17:48
Cette discussion concerne un article du site. Pour la consulter dans son contexte d'origine, cliquez sur le lien ci-dessous.

https://codes-sources.commentcamarche.net/source/114-tri-d-un-objet-grid-a-partir-d-une-colone-referente

tdihedi Messages postés 3 Date d'inscription mardi 6 avril 2004 Statut Membre Dernière intervention 4 mai 2004
4 mai 2004 à 17:48
Mais je crois que la meilleure solution reste quand même

Grid.Sort = 1

c'est beaucoup plus rapide
tdihedi Messages postés 3 Date d'inscription mardi 6 avril 2004 Statut Membre Dernière intervention 4 mai 2004
4 mai 2004 à 14:24
Merci pour l'auteur de ce code

Si vous essayez ce code vous allez voir qu'il ya quelques bugs:
par exemple le fait que la ligne de titre soit incluse

voici le code modifié:

Private Sub SortedGrid(ByVal Col As Integer)
Dim ct As Integer, ct2 As Integer, swapRow As Integer
Dim curVal, oldVal
Dim Change As Boolean


If Col < 0 And Col > Grid.Cols - 1 Then Exit Sub

Change = True

Do While Change
Change = False
For ct = Grid.Rows - 1 To Grid.FixedRows Step -1
Grid.Row = ct
Grid.Col = Col
oldVal = Grid.Text
swapRow = ct

For ct2 = ct To Grid.FixedRows Step -1
Grid.Row = ct2
Grid.Col = Col

If oldVal < Grid.Text Then
Call SwapRowGrid(swapRow, ct2)
swapRow = ct2
Change = True
ElseIf oldVal > Grid.Text Then
Exit For
End If
Next
Next
Loop

End Sub
Rejoignez-nous