Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question about CConlistListBox.

Status
Not open for further replies.

FORAND

Programmer
May 26, 2003
64
CA

I have a CControlListBox.
I selected 3 elements in it.
How can my program "unselect" one of them?

Thanks

Pierre
 
CControlListBox? Never heard of it.

I've heard of CListCtrl and CListBox though. Which are you using?

CListCtrl:
theListCtrl.SetItemState(indexOfSelectedItem, 0, LVIS_SELECTED);

CListBox:
theListCtrl.SetSel(-1, FALSE);

/Per

"It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure."
 
Thanks!!!
And ...
it's a CListCtrl ;)

Thanks again !
 
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
 
See MSDN on the methods GetCurSel and SetCurSel

/Per

www.perfnurt.se
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top