以下是用于填充树 View 的代码。
我该如何选择默认项,例如星期一作为默认项。这样,无论何时加载对话框,总是选择星期一。
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()中执行
最佳答案
此代码位于 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();