在MFC

时间:2017-01-03 17:12:03

标签: c++ mfc treeview

以下是用于填充树视图的代码。 我怎样才能将选择默认值设置为 Monday 作为默认值。因此,无论何时加载对话,总是选择星期一

CTreeCtrl m_treeSettings;

HTREEITEM hParent, hChild;
hParent = m_treeSettings.InsertItem(_T("Week Days"), TVI_ROOT);
hChild = m_treeSettings.InsertItem(_T("Sunday"), hParent);
hChild = m_treeSettings.InsertItem(_T("Monday"), hParent);
hChild = m_treeSettings.InsertItem(_T("Tuesday"), hParent);
hChild = m_treeSettings.InsertItem(_T("Wednesday"), hParent);
hChild = m_treeSettings.InsertItem(_T("Thrasday"), hParent);
hChild = m_treeSettings.InsertItem(_T("Friday"), hParent);
hChild = m_treeSettings.InsertItem(_T("Saturday"), hParent);

m_treeSettings.Expand(hParent,TVE_EXPAND);

基本上它是一个CTreeCtrl,整个代码在 OnInitDialog()

中执行

Treeview Image as Required

1 个答案:

答案 0 :(得分:2)

此代码位于 OnInitDialog()。这有助于实现我想做的事情。如果有人有更好的解决方案,那么请指导。

HTREEITEM hParent, hMonday, hChild;
hParent = m_treeSettings.InsertItem(_T("Week Days"), TVI_ROOT);
hChild = m_treeSettings.InsertItem(_T("Sunday"), hParent);
hMonday = m_treeSettings.InsertItem(_T("Monday"), hParent);
hChild = m_treeSettings.InsertItem(_T("Tuesday"), hParent);
hChild = m_treeSettings.InsertItem(_T("Wednesday"), hParent);
hChild = m_treeSettings.InsertItem(_T("Thrasday"), hParent);
hChild = m_treeSettings.InsertItem(_T("Friday"), hParent);
hChild = m_treeSettings.InsertItem(_T("Saturday"), hParent);

m_treeSettings.Expand(hParent,TVE_EXPAND);
m_treeSettings.SelectItem(hMonday);
m_treeSettings.SetFocus();
相关问题