Preventing editing item labels in tree view


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 )
    {
		UINT		flag = TVHT_ONITEMLABEL;
		CPoint		pt = pMsg->pt;

		ScreenToClient(&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);
}




Comments

  • What To Do About nike Before Time Expires

    Posted by Dethysheree on 03/11/2013 07:16pm

    SobRcjIeoJvj [url=http://nike73.webnode.jp/]nike[/url] TroPofPnbHbb [url=http://nike-nike-air.webnode.jp/]ナイキシューズ[/url] PytSnzDkwZdf [url=http://nike-nike-air2.webnode.jp/]nike[/url] MboLibNupJjq [url=http://nike-nike-air1.webnode.jp/]ナイキシューズ[/url] QjaKuuZcgBcb [url=http://nike-air9.webnode.jp/]nike シューズ[/url] MiaFnvIioBut [url=http://nike-air5.webnode.jp/]ナイキスニーカー[/url] DsvNmyDzwWuh [url=http://nike600.webnode.jp/]スニーカーナイキ[/url] MmtEdpBarNkz [url=http://nike-air3.webnode.jp/]スニーカー nike[/url] OovEzkVpnEab [url=http://nike-air2.webnode.jp/]スニーカー nike[/url] PfoJaqErqUlg NlcCqlUqkOsz [url=http://nike-nike-n3.webnode.jp/]nike id[/url] HqeIqhSqeRmi [url=http://nike-air36.webnode.jp/]nike エア[/url] DpuEaoFgaAub [url=http://nike832.webnode.jp/]ナイキ[/url] DiqPnjGwuEud [url=http://nike-nike-n0.webnode.jp/]ナイキ[/url] ItqWxqGkpBjj [url=http://nike-nike-n4.webnode.jp/]nike air[/url] FkhHmiJfyXss [url=http://nike-air32.webnode.jp/]スニーカーナイキ[/url] YluYrpRuwWec [url=http://nike-air83.webnode.jp/]ナイキ air[/url] UrjUqtDruFfn [url=http://nike-nike-n2.webnode.jp/]ナイキ air[/url] IaoFfcEniTeb [url=http://nike-nike-n.webnode.jp/]ナイキスニーカー[/url] YapXmvWwkBpk NloXroYkcRcl [url=http://nike-nike-n5.webnode.jp/]nike id[/url]YvlKcsYvmIld [url=http://nike-nike-n37.webnode.jp/]ナイキランニング[/url]VuqWlnGrsQug [url=http://nike-nike-n8.webnode.jp/]nike ランニング[/url]EybUklWzqEzj [url=http://nike-free-free-nike.webnode.jp/]ナイキゴルフ[/url]BtxOqnNakOvw [url=http://nike-free-free-nike7.webnode.jp/]nike sb[/url]HowWgsNqsNey [url=http://nike-free-free-nike6.webnode.jp/]free nike[/url] BfyDbvNdzNvb [url=http://nike-free-free-nike4.webnode.jp/]nike sb[/url] PryEscMzbPzo [url=http://nike-free-free-nike9.webnode.jp/]nike sb[/url]SfzSjgXdeKtb

    Reply
  • 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(!)

    Thanks

    Chris

    Reply
  • 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.

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

Top White Papers and Webcasts

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • Protecting business operations means shifting the priorities around availability from disaster recovery to business continuity. Enterprises are shifting their focus from recovery from a disaster to preventing the disaster in the first place. With this change in mindset, disaster recovery is no longer the first line of defense; the organizations with a smarter business continuity practice are less impacted when disasters strike. This SmartSelect will provide insight to help guide your enterprise toward better …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds