GuyFALESSE
Messages postés61Date d'inscriptionsamedi 19 février 2005StatutMembreDernière intervention18 novembre 2012
-
24 avril 2005 à 15:19
maitrealino
Messages postés3Date d'inscriptiondimanche 9 octobre 2011StatutMembreDernière intervention21 décembre 2011
-
21 déc. 2011 à 22:15
Cette discussion concerne un article du site. Pour la consulter dans son contexte d'origine, cliquez sur le lien ci-dessous.
maitrealino
Messages postés3Date d'inscriptiondimanche 9 octobre 2011StatutMembreDernière intervention21 décembre 2011 21 déc. 2011 à 22:15
je trouve ça vraiment super! mille mercis
cs_scorpion1970
Messages postés1Date d'inscriptionmercredi 2 juillet 2003StatutMembreDernière intervention17 juin 2008 17 juin 2008 à 10:40
Public Sub SetGridColumnWidth(grd As MSFlexGrid)
Dim i, j As Integer
Dim lngLongestLen As Long
Dim sLongestString As String
For j = 0 To grd.Cols - 1
sLongestString = ""
lngLongestLen = 0
For i = 0 To grd.Rows - 1
If Len(grd.TextMatrix(i, j)) > lngLongestLen Then
lngLongestLen = Len(grd.TextMatrix(i, j))
sLongestString = grd.TextMatrix(i, j)
End If
Next
grd.ColWidth(j) = grd.Parent.TextWidth(sLongestString) + 10
Next
End Sub
lambdacrash
Messages postés31Date d'inscriptionvendredi 28 février 2003StatutMembreDernière intervention11 juillet 201013 8 août 2006 à 13:07
Bonjour,
Je propose plutôt ceci, c'est un morceau de code fait sur le coin du bureau. Il ne gère pas la longueur des headers.
Public Function dataGridAutoResize(oDataGrid As Object)
Dim i, j As Integer
Dim dataGridNumRows As Integer
Dim dataGridNumCols As Integer
Dim vBMark As Variant
Dim cellTextLength As Long
For j = 0 To dataGridNumCols
cellTextLength = 0
For i = 0 To dataGridNumRows
vBMark = DataGrid1.GetBookmark(i)
If cellTextLength < Len(oDataGrid.Columns(j).CellText(vBMark)) Then
cellTextLength = Len(oDataGrid.Columns(j).CellText(vBMark))
End If
Next
oDataGrid.Columns(j).Width = 100 * cellTextLength + 70
Next
End Function
tthiouwz
Messages postés1Date d'inscriptiondimanche 12 septembre 2004StatutMembreDernière intervention13 novembre 2005 13 nov. 2005 à 23:17
Ton code se base seulement sur la dernière ligne de la datagrid pour décider de la largeur des colonnes. Ca améliore la visibilité c'est sur, mais si l'enregistrement de cette ligne est beaucoup plus petit ou plus grand que les autres ca rend pas super. Le mieux aurait été de faire une moyenne de la largeur avec toutes les lignes puis y ajouter un coefficient comme tu fais ici. Dommage que je n'ai pas le temps pour le faire, du coup je prend ta source, ca me suffira :)
Bonne prog :)
gamani06
Messages postés8Date d'inscriptionjeudi 5 juin 2003StatutMembreDernière intervention14 juillet 2005 14 juil. 2005 à 12:04
Ton code ne marche pas
GuyFALESSE
Messages postés61Date d'inscriptionsamedi 19 février 2005StatutMembreDernière intervention18 novembre 2012 24 avril 2005 à 15:19
Salut,
Hé bien, moi, j'ai trouvé ça super.
Je suis débutant aussi.
21 déc. 2011 à 22:15
17 juin 2008 à 10:40
Dim i, j As Integer
Dim lngLongestLen As Long
Dim sLongestString As String
For j = 0 To grd.Cols - 1
sLongestString = ""
lngLongestLen = 0
For i = 0 To grd.Rows - 1
If Len(grd.TextMatrix(i, j)) > lngLongestLen Then
lngLongestLen = Len(grd.TextMatrix(i, j))
sLongestString = grd.TextMatrix(i, j)
End If
Next
grd.ColWidth(j) = grd.Parent.TextWidth(sLongestString) + 10
Next
End Sub
8 août 2006 à 13:07
Je propose plutôt ceci, c'est un morceau de code fait sur le coin du bureau. Il ne gère pas la longueur des headers.
Public Function dataGridAutoResize(oDataGrid As Object)
Dim i, j As Integer
Dim dataGridNumRows As Integer
Dim dataGridNumCols As Integer
Dim vBMark As Variant
Dim cellTextLength As Long
dataGridNumRows = oDataGrid.VisibleRows - 1
dataGridNumCols = oDataGrid.Columns.Count - 1
For j = 0 To dataGridNumCols
cellTextLength = 0
For i = 0 To dataGridNumRows
vBMark = DataGrid1.GetBookmark(i)
If cellTextLength < Len(oDataGrid.Columns(j).CellText(vBMark)) Then
cellTextLength = Len(oDataGrid.Columns(j).CellText(vBMark))
End If
Next
oDataGrid.Columns(j).Width = 100 * cellTextLength + 70
Next
End Function
13 nov. 2005 à 23:17
Bonne prog :)
14 juil. 2005 à 12:04
24 avril 2005 à 15:19
Hé bien, moi, j'ai trouvé ça super.
Je suis débutant aussi.
@+
Guy FALESSE