Ordinare manualmente i valori all'interno di una colonna di una GridView

Da Gambas-it.org - Wikipedia.

Per ordinare manualmente mediante trascinamento del mouse il testo contenuto nelle celle di una colonna di una GridView, si potranno adottare almeno le seguenti due modalità.

Mediante Drag&Drop

Public Sub Form_Open()

 With GridView1
   .Columns.Count = 3
   .Rows.Count = 5
   .Drop = True

   For b As Byte = 0 To .Columns.Max
     For c As Byte = 0 To .Rows.Max
       GridView1[c, b].Text = b & "-" & c
     Next
   Next
 End With

End


Public Sub GridView1_MouseDrag()

 GridView1.Drag(GridView1.Current.Text, "text/html")

End


Public Sub GridView1_Drop()

 With GridView1
   If .Column <> .ColumnAt(Mouse.ScreenX - Me.X - .X) Then Return   '[nota 1]
   Dim ss As New String[.Rows.Count]
   For r As Byte = 0 To GridView1.Rows.Max
     ss[r] = GridView1[r, .ColumnAt(Mouse.ScreenX - Me.X - .X)].Text
   Next

   ss.Remove(ss.Find(.Current.Text))
   ss.Add(Drag.Data, Fix(Drag.Y / (.ScrollH / .Rows.Count)))   '[nota 2]

   For b As Byte = 0 To .Rows.Max
     GridView1[b, .ColumnAt(Mouse.ScreenX - Me.X - .X)].Text = ss[b]
   Next
 End With 

End

Senza il Drag&Drop

Public Sub Form_Open()

 With GridView1
   .Columns.Count = 3
   .Rows.Count = 5

   For b As Byte = 0 To .Columns.Max
     For c As Byte = 0 To .Rows.Max
       GridView1[c, b].Text = b & "-" & c
     Next
   Next
 End With

End


Public Sub GridView1_Click()

 GridView1.Tag = [GridView1.Row, GridView1.Column]

End


Public Sub GridView1_MouseUp()
 
 With GridView1
   If .Column <> .Tag[1] Then Return
   Dim ss As New String[.Rows.Count]
   For b As Byte = 0 To .Rows.Max
     ss[b] = GridView1[b, .Column].Text
   Next
   
   ss.Remove(ss.Find(GridView1[.Tag[0], .Tag[1]].Text))
   ss.Add(GridView1[.Tag[0], .Tag[1]].Text, .Row)
   For b As Byte = 0 To .Rows.Max
     GridView1[b, .Column].Text = ss[b]
   Next
   
 End With

End


Note

[1] Un'altra modalità per trovare il numero d'indice della Colonna è:

Fix(Drag.X / (.ScrollW / GridView1.Columns.Count))

[2] Un'altra modalità per trovare il numero d'indice della Riga è:

GridView1.RowAt(Mouse.ScreenY - Me.Y - GridView1.Y)