Delete all items of a CListBox
-
-
I am trying to delete all items of a CListBox However, only the top item is removed once calling this routine, How do I delete everything ? Thanks
numOfItems= listBox.GetCount(); for (int i =0; i<=numOfItems; i++){ lisBox.DeleteString(i); }
llp00na
CListBox::ResetContent[^]. Btw there's also a fundamantal flaw in your method. Consider what your loop does: 1. i becomes 0, the very first ("zeroth") item is deleted from your list, this will raise all other items 1 place, so 0 goes away, 1st becomes the 0th, 2nd becomes 1st, 3rd becomes 2nd and so on... 2. i now becomes 1, the 1st item in your list is deleted, and the ones under it jump up one place, so the 0th item is untouched, the 1st is deleted, 2nd becomes 1st, 3->2, 4->3 ... 3. i now becomes 2, 2nd item is deleted, so 0th is untouched, 1st is untouched, 2nd is deleted, 3rd becomes 2bd, 4->3 and so on... Get the problem?
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <
-
CListBox::ResetContent[^]. Btw there's also a fundamantal flaw in your method. Consider what your loop does: 1. i becomes 0, the very first ("zeroth") item is deleted from your list, this will raise all other items 1 place, so 0 goes away, 1st becomes the 0th, 2nd becomes 1st, 3rd becomes 2nd and so on... 2. i now becomes 1, the 1st item in your list is deleted, and the ones under it jump up one place, so the 0th item is untouched, the 1st is deleted, 2nd becomes 1st, 3->2, 4->3 ... 3. i now becomes 2, 2nd item is deleted, so 0th is untouched, 1st is untouched, 2nd is deleted, 3rd becomes 2bd, 4->3 and so on... Get the problem?
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <
-
Great answer Thanks for the clarification. Looks like i can not think anymore :doh:
llp00na
Yourwelcome. :) If you want to stick to the for loop, try movings in reverse, so something like:
for (int I = Count - 1; I >= 0; I--)
listbox.DeleteString(I);or simply do this:
for (int I = 0; I < Count; I++)
listbox.DeleteString(0);> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <
-
Yourwelcome. :) If you want to stick to the for loop, try movings in reverse, so something like:
for (int I = Count - 1; I >= 0; I--)
listbox.DeleteString(I);or simply do this:
for (int I = 0; I < Count; I++)
listbox.DeleteString(0);> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <
-
I am trying to delete all items of a CListBox However, only the top item is removed once calling this routine, How do I delete everything ? Thanks
numOfItems= listBox.GetCount(); for (int i =0; i<=numOfItems; i++){ lisBox.DeleteString(i); }
llp00na