Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using the MSFlexGrid and Resizing Columns

Status
Not open for further replies.

Guru2B

Programmer
May 24, 2000
77
GB
Hello,

I have an application which has to display tabular data using some type of grid.

First, is the MSFlexGrid the best choice for this task? There seem to be quite a few grids at my disposal, including the ms - H - flexgrid. I need to be able to add data to the grid at run time and don't want it to be bound to the database.

Secondly, is there a way of resizing the columns in a grid to the text within it. I know I can set the colwidth to a pixel count, so is there anyway to obtain the pixel width of a word?

Thanks in advance
Guru2B
 
In anwer to your second question, drop a Picturebox onto your form, set the visible property to false, and then have a play with this code (strtext is the text you want to know the width of, srcControl is the control the text is in and is necessary so that we calculate width for the correct font):


Public Function GetTextPixelWidth(strText As String, srcControl As Control) As Long
Set Form1.Picture1.Font = srcControl.Font
Form1.Picture1.ScaleMode = vbPixels
GetTextPixelWidth = Form1.Picture1.TextWidth(strText)
End Function
 
Thanks Strongm,

Thanks for the reply. This method will certainly help me in many areas of coding...

..only...the code works as long as the string contains only alpha chars. If it contains spaces or numbers (I haven't checked with punctuation) the calculation is incorrect and the control is resized incorrectly. Is there any way to overcome this? I will have to store numeric and textual data in the columns.

Thanks again,
Guru2B
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top