Could someone please help me with SetSel() for CListBox controls? I've been through the MSDN help pages but can't find anything to explain what I'm seeing.
I put 3 strings into the list using the following code, which is in OnInitDialog() :
CListBox *p;
int s;
p = (CListBox*) GetDlgItem (IDC_LIST1);
s = p->AddString ("String 1");
s = p->AddString ("String 2");
s = p->AddString ("String 3");
AddString() returns 0, 1 then 2 and the strings are displayed ok in the dialog.
When I select an option, this code is run:
void CListsDlg::OnSelchangeList1()
{
int s, r;
CListBox *p;
// IDC_LIST1 previously set up with 3 options
p = (CListBox*) GetDlgItem (IDC_LIST1);
// Check whether each option is selected
s = p->GetSel (0);
s = p->GetSel (1);
s = p->GetSel (2);
// Deselect all options
r = p->SetSel (-1, false);
// Select option 1
r = p->SetSel (1, true);
}
GetSel() works fine but SetSel() always returns -1 and the selections I see on the dialog are not updated.
Any help much appreciated!
David