我想以编程方式设置要选择的树ctrl项的状态,然后在其他地方处理它。我想这样做是为了重用用户点击它时调用的代码。我试试这个,但它失败了,为什么?
// somewhere in the code
m_tree.SetItemState(hItemToBeSelected, TVIS_SELECTED, TVIS_SELECTED);
CommonFunction();
// elsewhere
CommonFunction()
{
HTREEITEM h = m_tree.GetSelectedItem();// this returns NULL.
}
我该怎么做?
答案 0 :(得分:2)
您想使用SelectItem而不是SetItemState:http://msdn.microsoft.com/en-us/library/w8hy20sy(v=VS.100).aspx