What wrong with this loop?
-
Hi all, i have an list ctrl with some items,i want to perform an action with each item of list ctrl than after performing action delete this item. i m using this.
//CListCtrl m_List;
int count =m_List.GetItemCount();
for (int i=0;ihere items are not fetched according to its serial like if firstly i m use item 1,than next item here is item 3 than 5 and so on..
here all items are not processes by this loop
please tell me what can i do for this.
thanks in advance.
-
Hi all, i have an list ctrl with some items,i want to perform an action with each item of list ctrl than after performing action delete this item. i m using this.
//CListCtrl m_List;
int count =m_List.GetItemCount();
for (int i=0;ihere items are not fetched according to its serial like if firstly i m use item 1,than next item here is item 3 than 5 and so on..
here all items are not processes by this loop
please tell me what can i do for this.
thanks in advance.
When you delete item 0, every other item moves up 1, so what was item 1 is now item 0. Instead of using
m_List.DeleteItem(i);
, usem_List.DeleteItem(0);
The same goes for getting the data or string from each of the items, you are always using the first item in the list -
Hi all, i have an list ctrl with some items,i want to perform an action with each item of list ctrl than after performing action delete this item. i m using this.
//CListCtrl m_List;
int count =m_List.GetItemCount();
for (int i=0;ihere items are not fetched according to its serial like if firstly i m use item 1,than next item here is item 3 than 5 and so on..
here all items are not processes by this loop
please tell me what can i do for this.
thanks in advance.
int count =m_List.GetItemCount(); for (int i=0;i<count;i++) { //do msometing with item i m_List.DeleteItem(0); } just like this。。
-
int count =m_List.GetItemCount(); for (int i=0;i<count;i++) { //do msometing with item i m_List.DeleteItem(0); } just like this。。
jixuduxing wrote:
//do msometing with item i
Probably just a copy/paste mistake, but
int count =m_List.GetItemCount();
for (int i=0;i<count;i++) {
//do something with item 0;m_List.DeleteItem(0);
} -
Hi all, i have an list ctrl with some items,i want to perform an action with each item of list ctrl than after performing action delete this item. i m using this.
//CListCtrl m_List;
int count =m_List.GetItemCount();
for (int i=0;ihere items are not fetched according to its serial like if firstly i m use item 1,than next item here is item 3 than 5 and so on..
here all items are not processes by this loop
please tell me what can i do for this.
thanks in advance.
Or even easier to understand:
//CListCtrl m_List;
int count =m_List.GetItemCount();
for (int i=0;i<count;i++)
{
//do someting with item i
}
m_List.DeleteAllItems();Peter "Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."
-
Hi all, i have an list ctrl with some items,i want to perform an action with each item of list ctrl than after performing action delete this item. i m using this.
//CListCtrl m_List;
int count =m_List.GetItemCount();
for (int i=0;ihere items are not fetched according to its serial like if firstly i m use item 1,than next item here is item 3 than 5 and so on..
here all items are not processes by this loop
please tell me what can i do for this.
thanks in advance.
-
Hi all, i have an list ctrl with some items,i want to perform an action with each item of list ctrl than after performing action delete this item. i m using this.
//CListCtrl m_List;
int count =m_List.GetItemCount();
for (int i=0;ihere items are not fetched according to its serial like if firstly i m use item 1,than next item here is item 3 than 5 and so on..
here all items are not processes by this loop
please tell me what can i do for this.
thanks in advance.
Note that reversing the loop
for (int i = count-1; i >= 0; i--)
{
//do msometing with item im_List.DeleteItem(i);
}would solve you problem.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Hi all, i have an list ctrl with some items,i want to perform an action with each item of list ctrl than after performing action delete this item. i m using this.
//CListCtrl m_List;
int count =m_List.GetItemCount();
for (int i=0;ihere items are not fetched according to its serial like if firstly i m use item 1,than next item here is item 3 than 5 and so on..
here all items are not processes by this loop
please tell me what can i do for this.
thanks in advance.