MFC control keyhole

Yugeen Klimenko <yugklim-/[email protected]> Wed, 24 Sep 2003 08:07:38 -0700 (PDT)
Newsgroups gmane.comp.programming.keyholes
Message-ID <[email protected]>
--===============10266058740279727==
Content-Type: multipart/alternative; boundary="0-1140205726-1064416058=:79270"

--0-1140205726-1064416058=:79270
Content-Type: text/plain; charset=us-ascii

How could I delete some or all the items from MFC combobox? I saw 
the sample code in MSDN Article on CComboBox::DeleteString()  :
// The pointer to my combo box.
extern CComboBox* pmyComboBox;
// Delete every other item from the combo box.
for (int i=0;i < pmyComboBox->GetCount();i++)
{
   pmyComboBox->DeleteString( i );
}
And it doesn't work. The first reason is that GetCount( ) (i.e. the 
number of items in the combo box) is calculated during each iteration 
and result of such a cycle is unpredictable ( I'm not talking about 
effectivity). The second one is that the number of item bein deleted 
changes in unpredictable manner . This is due to DeleteString( i ) 
inside a loop !
So, correct code looks like this:
int combo_size = pmyComboBox->GetCount();
for (int i=0; i < combo_size; ++i)
{
   pmyComboBox->DeleteString( 0 );
}
All that looks simple but at the same time resembles well known 
STL algorithms vs. cycles dilemma  (Meyers "Effective STL"). So, 
I thought how could it be good for us if the developers of MFC used STL
containers in the controls like CComboBox so that we could use 
STL algorithms.

 




---------------------------------
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
--0-1140205726-1064416058=:79270
Content-Type: text/html; charset=us-ascii

<DIV>How could I delete some or all the items from MFC combobox? I saw <BR>the sample code in MSDN Article on CComboBox::DeleteString()&nbsp; :</DIV>
<DIV>// The pointer to my combo box.<BR>extern CComboBox* pmyComboBox;<BR>// Delete every other item from the combo box.<BR>for (int i=0;i &lt; pmyComboBox-&gt;GetCount();i++)<BR>{<BR>&nbsp;&nbsp; pmyComboBox-&gt;DeleteString( i );<BR>}</DIV>
<DIV>And it doesn't work. The first reason is that GetCount( ) (i.e. the <BR>number of items in the combo box) is calculated during each iteration <BR>and result of such a cycle is unpredictable ( I'm not talking about <BR>effectivity). The second one is that the number of item bein deleted <BR>changes in unpredictable manner . This is due to DeleteString( i ) <BR>inside a loop !</DIV>
<DIV>So, correct code looks like this:</DIV>
<DIV>int combo_size = pmyComboBox-&gt;GetCount();<BR>for (int i=0; i &lt; combo_size; ++i)<BR>{<BR>&nbsp;&nbsp; pmyComboBox-&gt;DeleteString( 0 );<BR>}</DIV>
<DIV>All that looks simple but at the same time resembles well known <BR>STL algorithms vs. cycles dilemma&nbsp; (Meyers "Effective STL"). So, <BR>I thought how could it be good for us if the developers of MFC used STL<BR>containers in the controls like CComboBox so that we could use </DIV>
<DIV>STL&nbsp;algorithms.</DIV>
<DIV><BR>&nbsp;</DIV><BR><BR><p><hr SIZE=1>
Do you Yahoo!?<br>
<a href="http://us.rd.yahoo.com/evt=10469/*http://sitebuilder.yahoo.com">Yahoo! SiteBuilder</a> - Free, easy-to-use web site design software
--0-1140205726-1064416058=:79270--

--===============10266058740279727==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
software-keyholes mailing list
software-keyholes-xIg/pKzrS18HpDbxM/[email protected]
http://artima1.inetu.net/mailman/listinfo/software-keyholes

--===============10266058740279727==--