Click here to Skip to main content
15,897,718 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I wrote:
hItem = m_tree1.InsertItem(L"Car Listing", TVI_ROOT);
hCar = m_tree1.InsertItem(L"Economy", hItem);
m_tree1.InsertItem(L"BH-733", hCar);
m_tree1.InsertItem(L"SD-397", hCar);
m_tree1.InsertItem(L"JU-538", hCar);
m_tree1.InsertItem(L"DI-285", hCar);
m_tree1.InsertItem(L"AK-830", hCar);
hCar = m_tree1.InsertItem(L"Compact", hItem);
m_tree1.InsertItem(L"HG-490", hCar);
m_tree1.InsertItem(L"PE-473", hCar);
hCar = m_tree1.InsertItem(L"Standard", hItem);
m_tree1.InsertItem(L"SO-398", hCar);
m_tree1.InsertItem(L"DF-438", hCar);
m_tree1.InsertItem(L"IS-833", hCar);
hCar = m_tree1.InsertItem(L"Full Size", hItem);
m_tree1.InsertItem(L"PD-304", hCar);
hCar = m_tree1.InsertItem(L"Mini Van", hItem);
m_tree1.InsertItem(L"ID-497", hCar);
m_tree1.InsertItem(L"RU-304", hCar);
m_tree1.InsertItem(L"DK-905", hCar);
hCar = m_tree1.InsertItem(L"SUV", hItem);
m_tree1.InsertItem(L"FE-948", hCar);
m_tree1.InsertItem(L"AD-940", hCar);
hCar = m_tree1.InsertItem(L"Truck", hItem);
m_tree1.InsertItem(L"HD-394", hCar);



I want to obtain hcar when I click on a hcar tree Control

I wrote:

void CMFCApplication9Dlg::OnNMDblclkTree2(NMHDR *pNMHDR, LRESULT *pResult)
{
	// TODO: Add your control notification handler code here
	*pResult = 0;
	CString sText = m_tree1.GetItemText(hCar);
	m_text.SetWindowText(sText);

}


but on my Edit control it's written truck..I don't know why

What I have tried:

I want word everytime where I click..how can I write?
Posted
Updated 23-Sep-19 5:40am

You will need to override LVN_ITEMCHANGED message. It should look something like this:

C++
void CPageAddSearchStep2::OnItemchanged(NMHDR *pNMHDR, LRESULT *pResult)
{
   LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
   m_nSelection = pNMLV->iItem; // Item index
   *pResult = 0;
}
 
Share this answer
 
Because it's the last item in the list of items you added - and you are using that to access the text directly in the DoubleClick handler.

Instead, you need to get the selected item from the Tree control, and use the text from that. The NM_DBLCLK notification doesn't even tell you what was double clicked, so you need to identify that Tree control, then ask that for the selected item(s).
 
Share this answer
 
To get the selected item you should use the function CTreeCtrl::GetSelectedItem and NOT rely on some previous handle. This may change in your control flow.

I would recommand that you read the treecontrol documentation completly because it is some tricky class which needs some knowledge. Trust me: spending this time will avoid you a lot of headache.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900