CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2009
    Posts
    23

    Auto Resizing CListCtrl columns as Dialog is resized

    Hi,

    I have a CListCtrl with 2 columns. Right now the CListCtrl expands and shrinks as the dialog is resized, however the columns do not resize, what i am trying to do is to divide the width of the CListCtrl equally among the 2 columns. I have tried using SetColumnWidth without much luck, heres the code:
    Code:
    CRect rect;
    int newWidth;
    if(m_pList->GetSafeHwnd())
    {	
    	m_pList->GetWindowRect(rect);
    	ScreenToClient(rect);	
    	newWidth = (rect.right-rect.left)/2;
    	rect.right = rect.left + cx - 20;
    	m_pList->SetColumnWidth(0,newWidth);
    	m_pList->SetColumnWidth(1,newWidth);
                    m_pList->MoveWindow(rect);
    }
    how can this be done?

    Thanks

  2. #2
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Auto Resizing CListCtrl columns as Dialog is resized

    A couple of notes:

    1. Is this called in the OnSize handler for your dialog?

    2. You might need to call m_pList->MoveWindow(rect) before calling the SetColumnWidth on the columns (I just looked at working code and I call it before).

    3. Instead of GetWindowRect() and ScreenToClient, just call GetClientRect(). It will more accurately represent the size for your control, and does the coordinate conversion internally.

  3. #3
    Join Date
    May 2009
    Posts
    23

    Re: Auto Resizing CListCtrl columns as Dialog is resized

    hi,

    thanks for your response, sorry about my taking so long to post back. I just got around to fixing this, Its fixed.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured