m_ListCtrl.GetSelectedCount() ???

Started by
2 comments, last by greldik 18 years, 11 months ago
I have a listcontrol with no items selected and still when I run this function, the code is not executed?!? Am I missing something?

if (m_ListCtrl.GetSelectedCount() == 0)
{
	MessageBox("Please select 1 item!") ;
	return ;
}

Advertisement
There could be a number of things.

1. The if statement is not reached in the first place
2. You actually do have some item selected
3. If the listctrl is not initialized properly an error might be returned

Why don't you print out what GetSelectedCount returns? And also print out the selected items.
thx, I just tried your second answer and it indeed says that there is 1 selection, although nothing is selected, what is going on?!?
Well I've never had that problem. What item is selected according to your listbox? What happens if you do select a couple of items? Does it still return 1 or the actual number? Are you sure you are checking the correct list ctrl? Double check DoDataExchange if the listctrl is connected to a dialog resource. Add a selection changed event to the ctrl and set a break in that function...

Don't be afraid to debug your application. =)

You could also create a small test program where the bug occurs and post it here.

This topic is closed to new replies.

Advertisement