Link to home
Start Free TrialLog in
Avatar of cox8355
cox8355

asked on

Clearing MFC Combo Box for repopulating

I have a combo box whose displayed list is dependent upon another user selection. When the user makes the selection,
the code:

  ModelCount = m_modelCombo.GetCount();

  for (i=0; i<ModelCount; i++)
    m_modelCombo.DeleteString(i);

is executed. The combo box "m_modelCombo" is the given new values through the AddString method.

The new values are being displayed, but the previous values are partially left over, and the list continues to grow with each update attempt. What am i missing?

Randy
Avatar of fuzzyjon79
fuzzyjon79

Have you tried using UpdateData(TRUE) to your code?  I would add the UpdateData(TRUE); line right underneath the m_modelCombo.DeleteString(i); line.  If that does not work try using UpdateData(FALSE);  I can't remember which one would work but try either one to see if that fixes your problem.  Hope that this helps.


Jon
hi
Instead of using AddString; use InsertString.

for (int i=0; i<m_combo1.GetCount(); i++)
     m_combo1.DeleteString(i);
m_combo1.InsertString(0,"*.iii");
m_combo1.InsertString(1,"*.kkk");

That shall do the work for you

Avatar of cox8355

ASKER

Thanks...but...tried both of these, but the problem remains. Portions of the previous list still linger after supposedly being deleted. For example, this is what typically happens:

First list:     Second list:   ...etc.

1st_Item_1      2nd_Item_1
1st_Item_2      2nd_Item_2
1st_Item_3      2nd_Item_3
1st_Item_4      2nd_Item_4
1st_Item_5      2nd_Item_5
                1st_Item_2
                1st_Item_4

Any other ideas?

Thanks

This codes works perfectly well
Check it out


     int temp=m_combo1.GetCount();
     int text1;
     
     for(int i=temp;i>=0;--i)
          text1=m_combo1.DeleteString(i);
         
     
     
     m_combo1.InsertString(0,"hi");
     m_combo1.InsertString(1,"hello");
     
     m_combo1.SetCurSel(0);


ASKER CERTIFIED SOLUTION
Avatar of subhadeepin
subhadeepin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cox8355

ASKER

Thanks!

Still somewhat of a mystery for this reason...I was going from element 0 to (GetCount-1), where your loop was (GetCount) to 0.

I thought if GetCount returned, say, 10, that the elements would be referenced from 0 to 9. Your loop deletes elements 10 through 0....one more than it seems it should...??? Maybe I'm missing something that I'll see later...but it works.

Many thanks,
Randy
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No comment has been added lately, so it's time to clean up this TA. I will
leave a recommendation in the Cleanup topic area that this question is:

Answered: Points split between subhadeepin and LSkywalker

Please leave any comments here within the next seven days.

Experts: Silence means you don't care. Grading recommendations are made in light
of the posted grading guidlines (https://www.experts-exchange.com/help.jsp#hi73).

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

-bcl (bcladd)
EE Cleanup Volunteer