Hi Friends,

how can i change the columns width in MSflexgrid by code from 1.jpg to 2.Jpg

I have copied this code in my Module:

Public Function Grid_AutoSize(oGrid As MSFlexGrid, oLabel As Label)
  Dim nRow As Long
  Dim nCol As Long
  Dim nWidth As Long
  Dim nMaxWidth As Long
  ' Setzen der Eigenschaften
  With oLabel
    With .Font
      .Name = oGrid.Font.Name
      .Size = oGrid.Font.Size
      .Bold = oGrid.Font.Bold
      .Italic = oGrid.Font.Italic
      .Strikethrough = oGrid.Font.Strikethrough
      .Underline = oGrid.Font.Underline
    End With
    ' Wichtig!
    .WordWrap = False
    .AutoSize = True
  End With
  ' Auswerten und Setzen der Grössen
  With oGrid
    For nCol = .FixedCols To .Cols - 1
      nMaxWidth = 0
      For nRow = .FixedRows To .Rows - 1
        oLabel.Caption = .TextMatrix(nRow, nCol)
        nWidth = oLabel.Width
        If nWidth + 100 > nMaxWidth Then nMaxWidth = nWidth + 100
      Next nRow
      .ColWidth(nCol) = nMaxWidth
    Next nCol
  End With
End Function

and i have called this function in my Form Load

Grid_AutoSize msf1, lbltemp

Dim m As Long
For m = 1 To msf1.Cols + 1
  msf1.ColWidth(-1) = 1400

can u please help me




Try This :

msf1.ColWidth(0) = 400
msf1.ColWidth(1) = 1000
msf1.ColWidth(2) = 1200
msf1.ColWidth(3) = 1200
msf1.ColWidth(4) = 1500

With a little bit of judgement, you can do it..


Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.