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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

listbox count???

Status
Not open for further replies.

computerwhiz

Programmer
May 1, 2002
28
US
I am trying to find the count of items in my listbox and then delete those items but when I retrieve the count I get half of what I should. I have tried both ways of getting the listbox count.

example:

my listbox has 10 entries, the count would come back as 5.
my listbox has 3 entries, the count would come back as 2.

Code:
case IDC_BUTTON3:
{
  //UINT cnt = SendMessage(hwndLB,(UINT) LB_GETCOUNT, 0, 0);
  DWORD cnt = GetListBoxInfo(hwndLB);
  for(int a = 0; a <= cnt-1; a++)
  {
    SendMessage(hwndLB, LB_DELETESTRING, a, 0);
  }
  break;
}
 
Don't foregt, when a is incrementing and deleting, the number of items changes, and when a is greater than a half, you already overun the number of items :)

So unsetad of
SendMessage(hwndLB, LB_DELETESTRING, a, 0);
use
SendMessage(hwndLB, LB_DELETESTRING, 0, 0);


Ion Filipski
1c.bmp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top