首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

关于CListBox解决办法

2012-03-31 
关于CListBoxC/C++ code// Delete every other item from the list box.for (int i 0 i m_myListBox.

关于CListBox

C/C++ code
// Delete every other item from the list box.for (int i = 0; i < m_myListBox.GetCount(); i++){   m_myListBox.DeleteString(i);}


上面是MSDN上的一段代码,意思是删除ListBox的所有项,
可是,这代码应该错了吧?
假如ListBox中是10个项的话,当n=5的时候,就退出了循环了,
也就还剩下5个没有被删除,
不知道我有没有理解错?


[解决办法]
你理解是正確的。

i Cnt Del Slack_cnt
------------------------
0 10 0 9
1 9 1 8
2 8 2 7
3 7 3 6
4 6 4 5
5 5 x x -----> exit for loop.
[解决办法]
C/C++ code
// Delete every other item from the list box.int n=m_myListBox.GetCount();for (int i = n-1; i>=0 ; i--) m_myListBox.DeleteString(i); 

热点排行