| | | | Browse by category |
Problem
How do I resize the client area of a grid view to fit the width or height of the grid?
Cause
Action
The following function will calculate the grid's width and height and resize the parent frame accordingly. You can call this function from your OnInitialUpdate() routine.
void C1stGridView::FitToSize() { |
||||
UpdateFontMetrics(); CFrameWnd* pFrame = GetParentFrame(); CMDIChildWnd* pMDIChild = NULL; CWnd* pMDIClient = NULL; CRect oClientRect; if (pFrame && pFrame->IsKindOf(RUNTIME_CLASS(CMDIChildWnd))) |
||||
pMDIChild = (CMDIChildWnd*) pFrame; pMDIClient = pFrame->GetParent(); pMDIChild->MDIRestore(); pMDIClient->GetClientRect(&oClientRect);
int colTotalHeight = CalcSumOfRowHeights(0,GetRowCount(), oClientRect.Height()); // Check if the calculated value |
||||
colTotalWidth += ::GetSystemMetrics(SM_CXVSCROLL); | ||||
colTotalWidth += 7*(::GetSystemMetrics(SM_CXEDGE));
if (colTotalWidth >= oClientRect.Width()) |
||||
colTotalHeight += ::GetSystemMetrics( SM_CYHSCROLL); | ||||
colTotalHeight += 7*(::GetSystemMetrics(SM_CYEDGE));
// Add the window title bar to the height pFrame->SetWindowPos(NULL, 0, 0, colTotalWidth,colTotalHeight, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER); |
||||
} | ||||
} |