以下是用于填充树视图的代码。 我怎样才能将选择默认值设置为 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()
中执行答案 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();