POSSO MUDAR POSI?ÃO DE UM ITEM NO DATAGRIDVIEW?

MARCOS 29/11/2016 09:19:34
#469304
Bom dia,Colegas!
Minha dúvida é simples:

Tenho um objeto DataGridWiew , no meu projeto VB.NET.
No Grid, tenho 10 colunas, e cerca de 15 linhas.

Ocorre que em determinadas situações, eu preciso fazer com que ,por exemplo , a sétima linha
do Grid, passe a ser a terceira do Grid. Ou seja,mude de posição.
Antes,de eu criar um código para isto, gostaria de saber se já existe um método pronto no objeto, que permita
realizar esta mudança.

Agradeço qualquer orientação
DAMASCENO.CESAR 29/11/2016 17:43:21
#469313
até onde vai meu conhecimento, nunca ouvi falar que fosse possível fazer, mas voce pode carregar o grid em rotinas diferentes com as linhas na ordem que voce quiser, aí, de acordo com a necessidade, voce recarrega o grid com a rotina mantgendo as linhas na ordem que voce quer
NILSONTRES 29/11/2016 18:28:32
#469315
Resposta escolhida
Eu bolei algo assim e que funciona.
[ô]botão que move a linha para cima
Private Sub BTN_UP_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN_UP.Click
If GRID_LISTA.Rows.Count < 1 Then Exit Sub
Me.MoveLinha(Me.GRID_LISTA.CurrentRow, GRID_LISTA.CurrentRow.Index - 1)
End Sub

[ô]botão que move a linha para baixo
Private Sub BTN_DOW_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN_DOW.Click
If GRID_LISTA.Rows.Count < 1 Then Exit Sub
Me.MoveLinha(Me.GRID_LISTA.CurrentRow, GRID_LISTA.CurrentRow.Index + 1)
End Sub

Private Sub MoveLinha(ByVal pLinha As DataGridViewRow, ByVal pPosicao As Integer)
Try
If pPosicao < 0 Then Exit Sub
If pPosicao > GRID_LISTA.Rows.Count - 1 Then Exit Sub
Me.GRID_LISTA.Rows.Remove(pLinha)
Me.GRID_LISTA.Rows.Insert(pPosicao, pLinha)
My.Application.DoEvents()
Me.GRID_LISTA.Focus()
Me.GRID_LISTA.CurrentCell = GRID_LISTA.Rows(pPosicao).Cells(2)
Me.GRID_LISTA.Rows(pPosicao).Selected = True
[ô]*acerta os itens
Dim i As Integer
For i = 0 To GRID_LISTA.Rows.Count - 1
GRID_LISTA.Rows(i).Cells(GLITEM.Name).Value = i + 1
Next
Catch

End Try
End Sub

Selecione a linha que vc quer movimentar e movimente para cima ou para baixo.
KERPLUNK 29/11/2016 22:23:11
#469316
Se você está preenchendo seu grid com um List<T> basta adicionar uma propriedade [Ô]índice[Ô] na entidade e ordenar como quiser atribuindo o índice que quiser e usando o método de extensão OrderBy ou OrderByDescending.
MARCOS 08/12/2016 15:51:18
#469520
Obrigado,Pessoal !
Tópico encerrado , respostas não são mais permitidas