Click to See Complete Forum and Search --> : Please Help me find the corect size of my MSFlexGrid Control


Simon Pettman
March 30th, 1999, 03:32 AM
I am using the ActiveX control MSFlexGrid. I am trying to size the rows and

columns so that they fit neatly into the client area. I am using the

function below to do this. But It does not work, it produces a table that is

too large for the area. Either

1) The area returned from GetClientRect() is larger than it really is

2) The activeX control is not really using TWIPS as it says it is in the

instructions.

3) Or I am doing something stupid.

It is probably a case of the third option. I hope so other wise I will never

solve this!

Can anyone shed any light?

Simon Pettman

~~~~~~~~~~~~~~~~~~~~~~~~My Function~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

void CMlsfileView::SizeGrid(CMSFlexGrid &grid)

{

CDC* pDC=grid.GetDC(); // Get device context for grid window

pDC->SetMapMode(MM_TWIPS); // Set Mapping mode to MM_TWIPS

// Which are the units the MSFlexGrid

// Uses.

CRect rect; // Declare a RECT to recieve clientArea

grid.GetClientRect(&rect);// Get the Client area in device units

CSize size; // A SIZE struct

size=rect.Size(); // the size of client area in device units

pDC->DPtoLP(&size); // Convert the size into Logical units (TWIPS)

int fixedColWidth = grid.GetColWidth(0); // the width of fixed column

int fixedRowDepth = grid.GetRowHeight(0);// the depth of fixed row

// each non fixed column is equally sized

// remaining client area after fixed columns

// is diveded by the number of unfixed columns

int colwidth=(size.cx-fixedColWidth)/(grid.GetCols()-1);

// for now all rows including fixed are the same height

int rowdepth=size.cy/grid.GetRows();

// resizing each column

for (int i=1;i<grid.GetCols();i++)

{

// provide that there are less than 10 unfixed columns

if(grid.GetCols()-1<=10) grid.SetColWidth(i,colwidth);

else grid.SetColWidth(i,1200);

}

for (i=0;i<grid.GetRows();i++)

{

// same for rows

if(grid.GetRows()-1<=12) grid.SetRowHeight(i,rowdepth);

else grid.SetRowHeight(i,300);

}

}