Salut.
J'ai reussi a faire ce que je desirais, mais j'aimerais savoir s'il y a un moyen plus propre d'y parvenir. Si c'est le cas et si vous avez un exemple, je suis preneur. Car pour réussir, j'ai du utiliser 2 Flexgrid (1 pour l'entete, l'autre pour les lignes)
But :
Cliquer sur la colonne Entete (action=Tri dans l'exemple)
Redimensionnement de la colonne par l'utilisateur
Clique les les lignes
Utiliser les touches Flechees.
Selectionner une Ligne de l'exterieur (par la ListBox par exemple)
1 Form
1 MSFlexGrid (20cm de large 3cm de Haut)
1 MSFlexGrid (20cm de large 15cm de Haut) juste dessous la premiere
1 ListBox de 15cm de Haut a droite de la seconde Flexgrid
et vous copier le source
Merci d'avance.
Option Explicit
' SEC= Sub En Cours booleen pour empecher les appels recursifs inopines
Dim SEC_Chargement As Boolean
Dim SEC_AfficherLigneSelected As Boolean
Dim SEC_Trier As Boolean
Dim SEC_SelChange As Boolean
Dim LigneSelected As Integer
Dim stTriNew As String
Dim stTriOld As String
'*===============================================================================================
'* FORM --> LOAD
'*===============================================================================================
Private Sub Form_Load()
Call Charger
List1.ListIndex = 0
End Sub
'*===============================================================================================
'* Ajustement de la taille d'une colonne modifiee manuellement
'*************************************************************************************
Private Sub MSFlexGrid1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim i As Integer
Dim Modifie As Boolean
Modifie = False
With MSFlexGrid2
For i = 0 To .Cols - 1
If .ColWidth(i) <> MSFlexGrid1.ColWidth(i) Then
.ColWidth(i) = MSFlexGrid1.ColWidth(i)
Modifie = True
End If
Next
End With
If Modifie Then MSFlexGrid2.SetFocus
End Sub
Private Sub MSFlexGrid2_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
Call MSFlexGrid1_MouseMove(Button, Shift, x, y)
End Sub
'*===============================================================================================
'* Demande de Tri (clic gauche ou clic droit)
'*===============================================================================================
Private Sub MSFlexGrid1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
Call Trier(MSFlexGrid1.MouseCol)
End Sub
'*===============================================================================================
'* CONTROLE DU CHANGEMENT De selection (y compris les Touches Fleches)
'*===============================================================================================
Private Sub MSFlexGrid2_SelChange()
If SEC_SelChange = False And SEC_AfficherLigneSelected = False Then 'Pour empecher la recursivite
SEC_SelChange = True
LigneSelected = MSFlexGrid2.RowSel
Call AfficherLigneSelected
List1.ListIndex = Val(MSFlexGrid2.TextMatrix(LigneSelected, 0))
' Call List1_Click
SEC_SelChange = False
End If
End Sub
'*===============================================================================================
'* TRI De la COLONNE
'*===============================================================================================
Private Sub Trier(ByVal IndexTri As Integer)
Dim i, j As Integer
Dim NoEnregSelected As String
Dim SensTri As String
On Error GoTo ErreurFocus
SEC_Trier = True
NoEnregSelected = MSFlexGrid2.TextMatrix(MSFlexGrid2.RowSel, 0)
'comparaisn avec le precedent Tri (cette methode permet de comparer sur plusieurs colonnes si besoin
' le 1er car donne le sens, le 3 eme le no de colonne
' (Avec 4 Cols on aurait : D!4326 Trie en majeur sur Col4 puis 3 etc..)
stTriNew = "?!" & Trim$(Str$(IndexTri))
If Mid$(stTriNew, 3) = Mid$(stTriOld, 3) Then
If Left$(stTriOld, 1) = "A" Then
SensTri = "DESC"
stTriNew = Replace(stTriNew, "?", "D")
Else
SensTri = "ASC"
stTriNew = Replace(stTriNew, "?", "A")
End If
Else
SensTri = "ASC"
stTriNew = Replace(stTriNew, "?", "A")
End If
stTriOld = stTriNew
MSFlexGrid2.Col = IndexTri
If SensTri = "ASC" Then
MSFlexGrid2.Sort = flexSortStringAscending
Else
MSFlexGrid2.Sort = flexSortStringDescending
End If
MSFlexGrid1.TextArray(0) = "No"
MSFlexGrid1.TextArray(1) = "Colonnel"
MSFlexGrid1.TextArray(IndexTri) = MSFlexGrid1.TextArray(IndexTri) & " " & SensTri
'Restauration Ligne Selectionnee
For i = 0 To MSFlexGrid2.Rows - 1
If MSFlexGrid2.TextMatrix(i, 0) = NoEnregSelected Then
LigneSelected = i
Call AfficherLigneSelected
If SEC_Chargement = False Then MSFlexGrid2.SetFocus
Exit For
End If
Next i
SEC_Trier = False
ErreurFocus:
End Sub
'*===============================================================================================
'* AFFICHAGE DE LA LIGNE SELECTIONNEE
'*===============================================================================================
Private Sub AfficherLigneSelected()
SEC_AfficherLigneSelected = True
MSFlexGrid2.Col = 0
MSFlexGrid2.Row = LigneSelected
MSFlexGrid2.ColSel = MSFlexGrid2.Cols - 1
MSFlexGrid2.RowSel = LigneSelected
SEC_AfficherLigneSelected = False
End Sub
'*===============================================================================================
'* AFFICHAGE dans MSFlexGrid2 DE LA LIGNE SELECTIONNEE dans LST
'*===============================================================================================
Private Sub List1_Click()
Dim i As Integer
If SEC_AfficherLigneSelected = False And _
SEC_SelChange = False Then
For i = 0 To MSFlexGrid2.Rows - 1
If Val(MSFlexGrid2.TextMatrix(i, 0)) = List1.ListIndex Then
LigneSelected = i
Exit For
End If
Next i
Call AfficherLigneSelected
End If
End Sub
'*===============================================================================================
'* CHARGEMENT DES MSFlexGrid1 ET MSFlexGrid2 et Listbox
'*===============================================================================================
Private Sub Charger()
SEC_Chargement = True
List1.AddItem "0"
List1.AddItem "1"
List1.AddItem "2"
List1.AddItem "3"
List1.AddItem "4"
MSFlexGrid1.Rows = 1
MSFlexGrid1.Cols = 2
MSFlexGrid1.FixedCols = 0
MSFlexGrid1.SelectionMode = 1
MSFlexGrid1.AllowUserResizing = flexResizeColumns
MSFlexGrid2.Rows = 5
MSFlexGrid2.Cols = 2
MSFlexGrid2.FixedRows = 0
MSFlexGrid2.FixedCols = 0
MSFlexGrid2.SelectionMode = 1
MSFlexGrid2.ColWidth(0) = 800
MSFlexGrid2.ColWidth(1) = 1500
MSFlexGrid1.ColWidth(0) = 800
MSFlexGrid1.ColWidth(1) = 1500
MSFlexGrid1.TextArray(0) = "No "
MSFlexGrid1.ColAlignment(0) = flexAlignLeftCenter
MSFlexGrid1.TextArray(1) = "Colonne1 "
MSFlexGrid1.ColAlignment(1) = flexAlignLeftCenter
MSFlexGrid2.TextMatrix(0, 0) = "0"
MSFlexGrid2.TextMatrix(1, 0) = "1"
MSFlexGrid2.TextMatrix(2, 0) = "2"
MSFlexGrid2.TextMatrix(3, 0) = "3"
MSFlexGrid2.TextMatrix(4, 0) = "4"
MSFlexGrid2.TextMatrix(0, 1) = "C0"
MSFlexGrid2.TextMatrix(1, 1) = "A1"
MSFlexGrid2.TextMatrix(2, 1) = "E3"
MSFlexGrid2.TextMatrix(3, 1) = "B2"
MSFlexGrid2.TextMatrix(4, 1) = "D4"
SEC_Chargement = False
End Sub