ORDENAR UM GRID ARRASTANDO AS LINHAS MANUALMENTE
Quem pode me ajudar, quero ordenar um grid arrastando as linhas para cima ou para baixo, para colocar em ordem manualmente, quem sabe ?
Truque: já experimentas-te guardar os dados da linha selecionada em variáveis e depois retornar o conteudo da linha para a nova linha
Testei esse código e funciona. VÊ o resultado em anexo
[ô]**************************************
[ô] Name: Moving a row in FlexGrid
[ô] Description:There was a question asked in a posting by Pamela RAI on using a mouse wheel for the flex grid. Bob (rbender) asked how to move a row in a flex grid. Here is how I did it...
[ô] By: Tom Pydeski
[ô]
[ô] Assumes:this is easiest if this code is just pasted into the original submission from Pamela RAI:
[ô]http://www.planet-source-code.com/vb/scripts/ShowCode.asp?lngWId=1&txtCodeId=40122
[ô]
[ô]This code is copyrighted and has[ô] limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=55733&lngWId=1[ô]for details.[ô]**************************************
in declarations section of form
Dim lngResult As Long
Dim ButtonDown As Boolean
Dim RowToMove As Integer
Dim DestRow As Integer
Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
[ô]turn off the highlight feature
MSFlexGrid1.HighLight = flexHighlightNever
MSFlexGrid1.FocusRect = flexFocusHeavy
[ô]get the desired row to move
RowToMove = MSFlexGrid1.MouseRow
[ô]this lets us know we are clicking
ButtonDown = True
Label1.Caption = [Ô]Preparing to Move Row # [Ô] & RowToMove
End Sub
Private Sub MSFlexGrid1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
If ButtonDown = False Then
[ô]we haven[ô]t clicked yet, so just advise the row we are on
Label1.Caption = [Ô]Click Mouse button to Move Row # [Ô] & MSFlexGrid1.MouseRow
Exit Sub
End If
[ô]we have clicked, so advise of the start and current row
If MSFlexGrid1.MouseRow <> RowToMove Then
Label1.Caption = [Ô]Release Mouse button to Move Row # [Ô] & RowToMove & [Ô] to [Ô] & MSFlexGrid1.MouseRow
End If
End Sub
Private Sub MSFlexGrid1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim lRet As Long
Dim RowClip$
Dim MoveClip$
With MSFlexGrid1
DestRow = .MouseRow
[ô]check if we are still in the same row as we clicked
If DestRow = RowToMove Then Exit Sub
[ô]this is just a confirmation, you don[ô]t really need this but it shows you it worked
lRet = MsgBox([Ô]Do you want to move Row # [Ô] & RowToMove & [Ô] to [Ô] & DestRow, vbQuestion + vbYesNo, [Ô]Move Row?[Ô])
If lRet = vbYes Then
.Redraw = False
[ô]select the whole row for the cell clicked
.Row = RowToMove
.Col = 0
.RowSel = RowToMove
.ColSel = .Cols - 1
[ô]copy the whole row[ô]s data to a string
RowClip$ = .Clip
[ô]delete the moved row
.RemoveItem RowToMove
[ô]put the moved data to the new row
.AddItem RowClip$, DestRow
.Redraw = True
End If
End With
[ô]release the variable that says we have the button down
ButtonDown = False
End Sub
Tópico encerrado , respostas não são mais permitidas