Mark D.
2014-09-08T21:31:24Z
Using iGrid Control v5.00 build 0094 with Excel 2010.

I have a simple grid with 3 columns and I'd like to make each column 1/3 of the total grid width, with the last column extending out to fill any extra space. What is the easiest way to do this with 10Tec's iGrid?
Igor/10Tec
2014-09-09T15:29:50Z
The problem of VBA UserForms is that they measure controls in points (1/72 of an inch). I guess you try to use the iGrid.Width property in your calculations, but it does not work. A suitable solution can be the following:

Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetDeviceCaps Lib "Gdi32" (ByVal hDC As Long, ByVal nIndex As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hDC As Long) As Long
Private Const LOGPIXELSX As Long = 88

Public Property Get PointsPerPixelX() As Double
   Dim hDC As Long
   hDC = GetDC(0)
   PointsPerPixelX = 72 / GetDeviceCaps(hDC, LOGPIXELSX)
   ReleaseDC 0, hDC
End Property

Private Sub SetColumnWidthsToFillSpace()
   Const BORDER_WIDTH As Long = 4

   Dim lViewportWidth As Long
   lViewportWidth = iGrid1.Width / PointsPerPixelX - BORDER_WIDTH - IIf(iGrid1.VScrollBar.Visible, iGrid1.VScrollBar.Thickness, 0)
   
   Dim lColWidth As Long
   lColWidth = lViewportWidth / iGrid1.ColCount
   
   Dim iCol As Long
   For iCol = 1 To iGrid1.ColCount - 1
      iGrid1.ColWidth(iCol) = lColWidth
   Next
   iGrid1.ColWidth(iCol) = lViewportWidth - lColWidth * (iGrid1.ColCount - 1)
End Sub

The PointsPerPixelX function was borrowed from this source:

http://www.mrexcel.com/f...control-coordinates.html 
Mark D.
2014-09-09T20:54:40Z
Thanks Igor. It worked like a charm.