Disable clicking on selected report view columns

I have developed a short piece of code to disable clicking column headers for columns than cannot be sorted-by.

This code simply uses the customization of header control as presented in "Indicating sort order" article. I just added slight more functionality to that header control.

1. I define a prototype and a variable in a class declaration body:

	typedef BOOL (*ColumnCheckF)(void *,int,LPARAM);

	void SetCallback(ColumnCheckF checkf=NULL,void * cbdata=NULL)

	ColumnCheckF m_fColumnCheck;
	void *m_pCBData;

After a click in a header, I find out the column (and I try to be wise and not disable clicking to resize columns) and ask the callback if the click is allowed (TRUE returned) or not.

It means, in the header (class declaration), I add

	// handlers
	afx_msg void OnLButtonDown(UINT,CPoint);

and in the .CPP I add


void CCustHeaderCtrl::OnLButtonDown(UINT flags,CPoint pt)
	if (m_fColumnCheck!=NULL)
		HD_ITEM hditem;
		CClientDC dc(this);
		int offset=dc.GetTextExtent(_T(" "),1).cx*2;
		int x_coord=pt.x;

		int column=0;
		while (x_coord>((column==0)?0:offset))
			if (x_coord<hditem.cxy-offset)
				// falls inside - query the func
				if (!m_fColumnCheck(m_pCBData,column,hditem.lParam))
					// don't forward the message!


The side effect of this code - it disables dragging the "disabled" columns. (That's because the header control never hears of LButtonDown message - I filter it of.)


  • Is any demo source is possible

    Posted by Legacy on 11/05/2001 12:00am

    Originally posted by: anup

    I need some demo code for this, if possible please send it to me.
    Thanks in advance.

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

Top White Papers and Webcasts

  • Featuring Mary Wardley, VP, Enterprise Applications and CRM Software, IDC Live Event Date: Wednesday, November 16, 2016 10 AM PT / 1 PM ET Significant changes are coming to the contact center, with new technologies enabling better customer engagement, innovative journey analytics and streamlined proactive communications. But the future holds some amazing advances which will change the role of the contact center in tomorrow's organizations. This is a critical time to understand what's coming and how an agile …

  • The open source cloud computing project OpenStack has come a long way since NASA and Rackspace launched it in 2010. Backed by leading technology infrastructure providers including Cisco, Dell, EMC, HP, IBM, Intel, and VMware, OpenStack underpins significant workloads at an increasingly diverse set of organizations, including BWM, CERN, Comcast, eBay, and Wal-Mart. For CIOs engaged in broader programs to win, serve, and retain customers -- and refocus business technology (BT) spend -- a planned and pragmatic …

Most Popular Programming Stories

More for Developers

RSS Feeds

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