Solved

Decide FlexGrid colum widths at run time

Posted on 2000-04-06
3
352 Views
Last Modified: 2010-05-02
Hi,

Has anyone any ideas or suggestions as to how I can decide the width of my FlexGrid colums at run time. The FlexGrid is being populated by information from an Access DB.
e.g. An E-mail address column needs to be wider than a Telephone column. How can I allocate the correct colum width??

Any suggestions or help would be greatly appreciated.
cheers,
shovels
0
Comment
Question by:shovels
3 Comments
 
LVL 32

Expert Comment

by:bhess1
ID: 2690599
Do you want the column widths to match the maximum size in the column?  

If you are populating the grid in code, then you could try something like this:

Set the Font on either a Form or a PictureBox to match the font in your grid.  Then check the TextWidth property for the size in twips, add a buffer, and assign that width to the column.

This example assumes a PictureBox (Pic1) with the font set correctly:

Dim strTmp as String

msFlexGrid1.Row = I
msFlexGrid1.Col = J
strTmp = rs!eMailAddr
msFlexGrid1.Text = strTmp
lngTmp = Pic1.TextWidth(strTmp) + 200 ' 200 twip margins around text
If lngTmp > msFlexGrid1.ColWidth(J) Then
  msFlexGrid1.ColWidth(J) = lngTmp
End If
.....

If you just want to set the widths to some fixed value:  

In Form_Load, add code like this:

With msFlexGrid1
  .ColWidth(0) = 100
  .ColWidth(1) = 350
  .ColWidth(2) = 2000
End With
0
 
LVL 1

Accepted Solution

by:
prakashbitra earned 50 total points
ID: 2690601
Use Colwidth property to decide the Flexgrid column width. If it has n number of columns use

    Colwidth(nth column)
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2690606
Add a Picture box to your project and set its Visible property to False. The following routine will then got through the FlexGrid and Autosize the columns.. <smile>.

<----- Code Begin ----->

Private Sub x_MsFlexGrid_AutoSize()
With MSFlexGrid1

   MSFlexGrid1.Visible = False
   Picture1.Visible = False
   
   Dim lngBorder As Long
   Dim lngCol As Long
   Dim lngRow As Long
 
   lngBorder = 6 * Screen.TwipsPerPixelX
   
   ' Set all Column Widths to Minimum
   For lngCol = 0 To .Cols - 1
      .ColWidth(lngCol) = lngBorder
   Next lngCol
 
   ' Autosize
   For lngRow = 0 To .Rows - 1
      .Row = lngRow
      For lngCol = 0 To .Cols - 1
         .Col = lngCol
         If .Text <> "" _
         Then
            Picture1.FontBold = .CellFontBold
            Picture1.FontItalic = .CellFontItalic
            Picture1.FontName = .CellFontName
            Picture1.FontSize = .CellFontSize
            Picture1.FontStrikethru = .CellFontStrikeThrough
            Picture1.FontUnderline = .CellFontUnderline
            If (Picture1.TextWidth(.Text) + lngBorder) _
            > .ColWidth(lngCol) _
            Then
               .ColWidth(lngCol) = (Picture1.Width + lngBorder)
            End If
         End If
      Next lngCol
   Next lngRow
 
   MSFlexGrid1.Visible = True

End With
End Sub

<----- Code End ----->
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Excel object stays open 19 74
VBA: Personal Macro Retain/Highlight/Remove values in a selected column 4 30
clicking a shape in a frame array vb6 3 45
Help me. 3 54
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question