?
Solved

Clearing MFC Combo Box for repopulating

Posted on 2003-02-27
8
Medium Priority
?
887 Views
Last Modified: 2012-08-13
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
0
Comment
Question by:cox8355
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 

Expert Comment

by:fuzzyjon79
ID: 8038337
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
0
 

Expert Comment

by:subhadeepin
ID: 8039612
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

0
 

Author Comment

by:cox8355
ID: 8039842
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
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Expert Comment

by:subhadeepin
ID: 8040790

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);


0
 

Accepted Solution

by:
subhadeepin earned 100 total points
ID: 8040803
the problem is with the following loop

for (int i=0; i<m_combo1.GetCount(); i++)
    m_combo1.DeleteString(i);

As elements are deleted GetCount value reduces; so elements are left out not being deleted

The following code does the work You need to do


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


}
0
 

Author Comment

by:cox8355
ID: 8058895
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
0
 

Assisted Solution

by:LSkywalker
LSkywalker earned 100 total points
ID: 8070087
Try
m_Combo.ResetContent();

This will delete all items rather than for you to loop thru.

LS
0
 
LVL 11

Expert Comment

by:bcladd
ID: 9847481
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 (http://www.experts-exchange.com/help.jsp#hi73).

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

-bcl (bcladd)
EE Cleanup Volunteer
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question