Ensure (partial) visibility of a column


How to Help Your Business Become an AI Early Adopter

The following function ensures that a column is at least partially visible. Rex Myer provided a comparable function in his article "Multiline editable subitems", but his code relies on the list having an item with index 0, it steps through all columns to find the left border and finally, if a column overlaps the right border by just one pixel but still has a 200 pixel distance from the left, the column will be moved to the left border. Additionally, the following code provides the bPartialOK-Flag known from CListCtrl::EnsureVisible(). Usage should be pretty much obvious :)

This code was developed with VC++ 5.0 (SP3), Windows NT 4.0 (SP3) and the new COMCTL32.DLL (v4.72)

bool CMyListCtrl::EnsureColumnVisible(int nColumn, bool bPartialOK)
	CHeaderCtrl* pHeader = reinterpret_cast(GetDlgItem(0));

	CRect rcHeader;
	Header_GetItemRect(pHeader->m_hWnd, nColumn, &rcHeader);

	CRect rcClient;

	int nOffset = GetScrollPos(SB_HORZ);

		if((rcHeader.left - nOffset < rcClient.right) && (rcHeader.right - nOffset > 0))
			return true;

	int nScrollX = 0;

	if((rcHeader.Width() > rcClient.Width()) || (rcHeader.left - nOffset < 0))
		nScrollX = rcHeader.left - nOffset;
	else if(rcHeader.right - nOffset > rcClient.right)
		nScrollX = rcHeader.right - nOffset - rcClient.right;

	if(nScrollX != 0)
		CSize size(nScrollX, 0);

	return true;


  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • A leading provider of tools and services to the health care industry was looking to implement automated chargeback reports with aggregation of tiered storage usage across multiple business units and applications. When the company's storage administrators attempted to create this system in-house, their productivity took a huge hit and they discovered the task was too challenging, as well. Read this case study to learn how this company was able to increase storage utilization, reduce storage consumption, and …

  • Milliseconds matter. Make your systems faster with an uncompromising approach to designing and deploying your cloud foundation on IBM Cloud.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date