Home All Groups Group Topic Archive Search About

Column Width for MSFlexGrid

Author
18 Jan 2006 11:12 AM
Steven
I develop the application which contains MSFlexGrid to display data. When I
try to fill the grid with the text data, I want to adjust the column width
so that the width is adjusted to the maximum pixel width of the column text
data. I have a function to measure the pixel width of the string data,
however, I found that the parameter of the Set_ColWidth() function in
MSFlexGrid is not in pixel unit. How can I convert the pixel unit to the
unit which is using in MSFlexGrid?

Author
18 Jan 2006 1:23 PM
Herfried K. Wagner [MVP]
"Steven" <a@a.com> schrieb:
>I develop the application which contains MSFlexGrid to display data. When I
>try to fill the grid with the text data, I want to adjust the column width
>so that the width is adjusted to the maximum pixel width of the column text
>data. I have a function to measure the pixel width of the string data,
>however, I found that the parameter of the Set_ColWidth() function in
>MSFlexGrid is not in pixel unit. How can I convert the pixel unit to the
>unit which is using in MSFlexGrid?

MSFlexGrid uses twips, but .NET uses pixels.  You can use the code below to
convert pixels to twips:

\\\
Private m_TwipsPerPixelX As Integer
Private m_TwipsPerPixelY As Integer
....
Using g As Graphics = Me.CreateGraphics()
    m_TwipsPerPixelX = 1440 / g.DpiX
    m_TwipsPerPixelY = 1440 / g.DpiY
End Using
....
Me.MSFlexGrid1.ColWidth = 100 * m_TwipsPerPixelX
///

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>