Preventing editing item labels in tree view


How to Help Your Business Become an AI Early Adopter

This article was contributed by Marius Bakelis.

If we have created tree view control with the TVS_EDITLABELS style we can edit all its items labels. But sometimes we do need that not all tree view control items labels could be editable. So we must prevent editing of item labels we don't want to be editable. We can override the PreTranslateMessage() function:

BOOL CTreeCtrlX::PreTranslateMessage(MSG* pMsg) 
    if( pMsg->message == WM_LBUTTONDOWN )
		CPoint		pt = pMsg->pt;

		if( HitTest( pt, &flag ) == GetSelectedItem() 
			// && there you can check is the item which cannot be editable
			SetFocus();	//We must set focus to the tree view control
					//becouse it can have no focus

			return TRUE ;   // DO NOT process further

    return CTreeCtrl::PreTranslateMessage(pMsg);


  • Preventing editing item labels in tree view

    Posted by Legacy on 08/05/1999 12:00am

    Originally posted by: Chris Grieve

    This was a great help but it has a tiny buggette in the way that HitTest is used which stops you D&D ing something by the icon that is already selected. This is the correction;

    As before except;

    UINT flag = 0;

    if( ( ( tree.HitTest( pt, &flag ) == tree.GetSelectedItem()
    &&( flag & TVHT_ONITEMLABEL ) ) // new bit
    && ( FALSE ) ) // your check in here

    But I wouldn't have got this far without the original code(!)



  • Why not handle TVN_BEGINLABELEDIT notification?

    Posted by Legacy on 01/16/1999 12:00am

    Originally posted by: Peter Schregle

    A more straightforward way to inhibit label editing would be to handle the TVM_BEGINLABELEDIT notification. Return FALSE to allow and TRUE to cancel label editing.

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 …

  • How does this impact your content strategy? Content management markets are changing rapidly. Due to increased expectations of users, changes in IT and the need for organizations to rethink their digital strategy, Gartner has launched new Magic Quadrants (MQs) for Content Services Platforms (CSP) and Content Collaboration Platforms (CCP). These MQs have updated the definition of previous Enterprise Content Management (ECM) and Enterprise File Sync and Share (EFSS) markets respectively, and are tightly connected …

Most Popular Programming Stories

More for Developers

RSS Feeds

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