|
-
January 20th, 2000, 05:17 AM
#1
renaming tree control item ?
hi there!
I want to rename an item of a tree control. I used the following
code:
void CMyarchivDlg::OnBeginlabeleditTree1(NMHDR* pNMHDR, LRESULT* pResult)
{
CString sText;
TV_DISPINFO* pTVDispInfo = (TV_DISPINFO*)pNMHDR;
UpdateData(TRUE);
sText.Format("%s",m_MyTreeControl.EditLabel(m_MyTreeControl.GetSelectedItem()));
m_MyTreeControl.SetItemText(m_MyTreeControl.GetSelectedItem(),sText);
UpdateData(FALSE);
*pResult = 0;
}
Unfortunately it doesn't work.
Can anyone give my a hint what's wrong ?
THANX in advance
greetz
cheops
-
February 10th, 2000, 11:30 PM
#2
Re: renaming tree control item ?
You should not handle it in TVN_BEGINLABELEDIT notification handler. It is used for different purpose.
In TVN_ENDLABELEDIT notification handler, check for a pszText member of the TVITEM structure contained TV_DISPINFO* pTVDispInfo = (TV_DISPINFO*)pNMHDR.
If this member is empty do not do anything. Editing has been cancelled.
Only if otherwise set item text to pszText member.
All that UpdateData, and other stuff is not needed for this purpose.
You should check pszText and then:
m_MyTreeControl.SetItemText(pTVDispInfo->item.hItem, pTVDispInfo->item.pszText);
This is it!
I don't do it for ratings. Important is if you let me know if solution worked.
Good luck in your journey in a C++ land.
There are only 10 types of people in the world:
Those who understand binary and those who do not.
-
November 1st, 2005, 02:31 PM
#3
A followup, I am able to rename my items, but
I have a bit of a problem elsewhere.
I catch, using the ON_NOTIFY_REFLECT TVN_KEYDOWN, when the user presses delete, and I delete the tree item...
Unfortunately, sometimes the user presses delete in the slight pause that occurs after clicking on an item in the tree but before the item label becomes editable. Thus, the Tree item is deleted, in a sense, out from under the editing label. How can I, in the TVN_KEYDOWN message handler, prevent any label editing messages from being carried out?
-
November 1st, 2005, 04:15 PM
#4
Re: renaming tree control item ?
Can you do a check to see that the selected item is the same as the item that you are trying to edit?
Code:
void OnTvnBeginLabelEdit(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMTVDISPINFO pTVDispInfo = reinterpret_cast<LPNMTVDISPINFO>(pNMHDR);
if(pTVDispInfo->item.hItem != tree.GetSelectedItem())
{
//Don't allow the edit
*pResult = 1;
}
else
{
//Handle edit ...
*pResult = 0;
}
}
Good Luck!
-
November 1st, 2005, 04:43 PM
#5
Re: renaming tree control item ?
Thanks! I actually had the codes reversed and was setting pResult to 0 to disable instead of 1...I ended up with a variation of your suggestion, thanks again.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|