What is the magic incantation to select a row in a CListCtrl in report mode ?
-
I've look at different (many) suggested solutions but they are always failing me in some regards. I have a list control in report mode with the "always show selection" flag set in the resource editor. I have a button that will set the selection on a item in the list (a row). The code to set the selection is :
// the index is valid
m_PositionListBox.SetFocus();
m_PositionListBox.SetItemState(nItem, LVIS_SELECTED, LVIS_SELECTED);
m_PositionListBox.SetItemState(nItem, LVIS_FOCUSED, LVIS_FOCUSED);When I do the above, I see the selection change (highlighted), but then just disappears. Am I missing something ?
I'd rather be phishing!
-
I've look at different (many) suggested solutions but they are always failing me in some regards. I have a list control in report mode with the "always show selection" flag set in the resource editor. I have a button that will set the selection on a item in the list (a row). The code to set the selection is :
// the index is valid
m_PositionListBox.SetFocus();
m_PositionListBox.SetItemState(nItem, LVIS_SELECTED, LVIS_SELECTED);
m_PositionListBox.SetItemState(nItem, LVIS_FOCUSED, LVIS_FOCUSED);When I do the above, I see the selection change (highlighted), but then just disappears. Am I missing something ?
I'd rather be phishing!
Something seems amiss here. I dummied up a project with VS2008 and your code seems to do what is expected.
CONTROL "",IDC_LIST1,"SysListView32",LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP,14,15,278,153
...
BOOL CTempDlg::OnInitDialog()
{
CDialog::OnInitDialog();// m\_PositionListBox is a CListCtrl m\_PositionListBox.InsertColumn(0, \_T("Name"), LVCFMT\_LEFT, 100); m\_PositionListBox.InsertItem(0, \_T("Ford")); m\_PositionListBox.InsertItem(1, \_T("Chevrolet")); m\_PositionListBox.InsertItem(2, \_T("Honda")); m\_PositionListBox.InsertItem(3, \_T("Toyota")); m\_PositionListBox.InsertItem(4, \_T("GMC")); m\_PositionListBox.InsertItem(5, \_T("Jeep")); return TRUE;
}
...
void CTempDlg::OnBnClickedSet()
{
int nItem = 3;
m_PositionListBox.SetFocus();
m_PositionListBox.SetItemState(nItem, LVIS_SELECTED, LVIS_SELECTED);
}When I click the Set button, item #3 (Toyota) is selected (blue). If I then press the Tab key, focus goes to the OK button but item #3 stays selected (gray).
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
Something seems amiss here. I dummied up a project with VS2008 and your code seems to do what is expected.
CONTROL "",IDC_LIST1,"SysListView32",LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP,14,15,278,153
...
BOOL CTempDlg::OnInitDialog()
{
CDialog::OnInitDialog();// m\_PositionListBox is a CListCtrl m\_PositionListBox.InsertColumn(0, \_T("Name"), LVCFMT\_LEFT, 100); m\_PositionListBox.InsertItem(0, \_T("Ford")); m\_PositionListBox.InsertItem(1, \_T("Chevrolet")); m\_PositionListBox.InsertItem(2, \_T("Honda")); m\_PositionListBox.InsertItem(3, \_T("Toyota")); m\_PositionListBox.InsertItem(4, \_T("GMC")); m\_PositionListBox.InsertItem(5, \_T("Jeep")); return TRUE;
}
...
void CTempDlg::OnBnClickedSet()
{
int nItem = 3;
m_PositionListBox.SetFocus();
m_PositionListBox.SetItemState(nItem, LVIS_SELECTED, LVIS_SELECTED);
}When I click the Set button, item #3 (Toyota) is selected (blue). If I then press the Tab key, focus goes to the OK button but item #3 stays selected (gray).
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
THanks, I will bake a dummy project on my side either, see if there's something different. :thumbsup:
I'd rather be phishing!
-
Something seems amiss here. I dummied up a project with VS2008 and your code seems to do what is expected.
CONTROL "",IDC_LIST1,"SysListView32",LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP,14,15,278,153
...
BOOL CTempDlg::OnInitDialog()
{
CDialog::OnInitDialog();// m\_PositionListBox is a CListCtrl m\_PositionListBox.InsertColumn(0, \_T("Name"), LVCFMT\_LEFT, 100); m\_PositionListBox.InsertItem(0, \_T("Ford")); m\_PositionListBox.InsertItem(1, \_T("Chevrolet")); m\_PositionListBox.InsertItem(2, \_T("Honda")); m\_PositionListBox.InsertItem(3, \_T("Toyota")); m\_PositionListBox.InsertItem(4, \_T("GMC")); m\_PositionListBox.InsertItem(5, \_T("Jeep")); return TRUE;
}
...
void CTempDlg::OnBnClickedSet()
{
int nItem = 3;
m_PositionListBox.SetFocus();
m_PositionListBox.SetItemState(nItem, LVIS_SELECTED, LVIS_SELECTED);
}When I click the Set button, item #3 (Toyota) is selected (blue). If I then press the Tab key, focus goes to the OK button but item #3 stays selected (gray).
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
I've got it working with
m_PositionListBox.SetItemState(-1, 0, LVIS_SELECTED| LVIS_FOCUSED);
m_PositionListBox.SetItemState(currentStep - 1, LVIS_SELECTED| LVIS_FOCUSED, LVIS_SELECTED| LVIS_FOCUSED);Thanks.
I'd rather be phishing!