ecommerce web developer development freelance website designer India
Description:Automatically resize the columns in any flex grid to give a nice, professional appearance.

Public Sub AutosizeGridColumns(ByRef msFG 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 msFG
For I = 0 To .Cols - 1
' Loops through every column
.Col = I
' Set the active colunm
intRows = .Rows
' Set the number of rows
If intRows > MaxRowsToParse Then intRows = MaxRowsToParse
' If there are more rows of data, reset intRows to the MaxRowsToParse constant
intBiggestWidth = 0
' Reset some values to 0

For J = 0 To intRows - 1
' check up to MaxRowsToParse # of rows and obtain
' the greatest width of the cell contents
.Row = J
txtString = .Text
intTempWidth = TextWidth(txtString) + intPadding
' The intPadding constant compensates for text insets
' You can adjust this value above as desired.
If intTempWidth > intBiggestWidth Then intBiggestWidth = intTempWidth
' Reset intBiggestWidth to the intMaxCol Width value if necessary
Next J
.ColWidth(I) = intBiggestWidth
Next I
' Now check to see if the columns aren't as wide as the grid itself.
' If not, determine the difference and expand each column proportionately
' to fill the grid
intTempWidth = 0


For I = 0 To .Cols - 1
intTempWidth = intTempWidth + .ColWidth(I)
' Add up the width of all the columns
Next I

If intTempWidth < msFG.Width Then
' Compate the width of the columns to the width of the grid control
' and if necessary expand the columns.
intTempWidth = Fix((msFG.Width - intTempWidth) / .Cols)
' Determine the amount od width expansion needed by each column
For I = 0 To .Cols - 1
.ColWidth(I) = .ColWidth(I) + intTempWidth
' add the necessary width to each column
Next I
End If
End With
End Sub
Auto size flex grid column widths

901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050

Express News India | Freelance ecommerce web development India