Taille Automatique des colonnes dans MSHFlexgrid

SEB83200 Messages postés 34 Date d'inscription lundi 16 juin 2008 Statut Membre Dernière intervention 11 juin 2013 - 18 févr. 2009 à 18:33
xpert12 Messages postés 114 Date d'inscription lundi 5 février 2007 Statut Membre Dernière intervention 10 septembre 2010 - 18 févr. 2009 à 23:57
Bonjour,

Je voudrai savoir comment faire pour les colonnes de mon MSHFLEXGRID prennent une taille automatique en fonction du texte present dedans?

Merci

1 réponse

xpert12 Messages postés 114 Date d'inscription lundi 5 février 2007 Statut Membre Dernière intervention 10 septembre 2010
18 févr. 2009 à 23:57
salut,

en fait c'est assez simple. Utilise le code suivant :

Public Sub AutosizeGridColumns(ByRef myFlex As MSFlexGrid, ByVal MaxRowsToParse _
As Integer, ByVal MaxColWidth As Integer)
Dim I, J As Integer
Dim txtString As String
Dim intTempWidth, BiggestWidth As Integer
Dim intRows As Integer
Const intPadding = 150

With myFlex
For I = 0 To .Cols - 1
.Col = I
intRows = .Rows
If intRows > MaxRowsToParse Then intRows = MaxRowsToParse
intBiggestWidth = 0

For J = 0 To intRows - 1
.Row = J
txtString = .Text
intTempWidth = TextWidth(txtString) + intPadding
If intTempWidth > intBiggestWidth Then intBiggestWidth = intTempWidth
Next J
.ColWidth(I) = intBiggestWidth
Next I
intTempWidth = 0

For I = 0 To .Cols - 1
intTempWidth = intTempWidth + .ColWidth(I)
Next I

If intTempWidth < myFlex.Width Then
intTempWidth = Fix((myFlex.Width - intTempWidth) / .Cols)
For I = 0 To .Cols - 1
.ColWidth(I) = .ColWidth(I) + intTempWidth
Next I
End If
End With
End Sub

En espérant que ça puisse t'aider !!
0
Rejoignez-nous