Thread: Reset Combo Control VS C++ 6.0

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    164

    Reset Combo Control VS C++ 6.0

    I think I have a relatively simple question, yet I have not found a relatively simple solution.

    I am loading a combo box control using using .AddString ():
    Code:
    //list files in combo box box for data files
    m_DataFile.AddString(file.c_str());
    UpdateData(false);
    That works fine and I am pleased with my results. However, I want to be able to clear the values listed in the combo box based on the value of check box state. I successfully add values to the combo box if it is checked, but I want to clear the list in the combo box so it shows no values if the box is unchecked.

    So far the code below clears most of the values but some still remain, so I know this logic is flawed. Any suggestions? Am I going about this the wrong way?
    Code:
    //clear the combo box of current values
    		int count = 0;
    		//clear the combo box setting it blank values
    		do
    		{
    			m_DataFile.DeleteString(count);
    			UpdateData (false);
    			count ++;
    			
    		}while (count != numberPackages);
    Any help is greatly appreciated. Thanks-

  2. #2
    Madly in anger with you
    Join Date
    Nov 2005
    Posts
    211
    if you just want to clear all strings, something like this should suffice:

    Code:
    int iCount;
    
    for(iCount = ComboBox_GetCount(hwndCb); iCount; iCount--)
        ComboBox_DeleteString(hwndCb, iCount);
    where hwndCb is a handle to the combo box control/window.

  3. #3
    Registered User
    Join Date
    May 2004
    Posts
    164
    Thanks for the reply!

    to create the handle to the combo box, I am getting errors with my code. Looks like this:
    Code:
    HANDLE hwndCb;
    hwndCb = IDC_DATAFILE:
    Not accustom to creating handles to controls.... sorry....

    here is my return error:
    Code:
    C:\ASE\FXGPackageBuilder\PACKAGEEDIT.cpp(730) : error C2440: '=' : cannot convert from 'const int' to 'void *'
    Thanks for the help-

  4. #4
    Registered User
    Join Date
    May 2004
    Posts
    164
    I added a call to GetSafeHwnd () to try and correct my handle issue, which fixed that, then go errors relating the function listed for GetCount and DeleteString in relation to parameter passing:

    Code:
    for(iCount = m_DataFile.GetCount(hwndCb); iCount; iCount--);
    		m_DataFile.DeleteString(hwndCb, iCount);
    it basically says that GetCount does not take a parameter and that DeleteString only allows for one parameter.

    I modified my code to remove the parameter issues like this:
    Code:
    for(iCount = m_DataFile.GetCount(); iCount; iCount--);
    		m_DataFile.DeleteString(iCount);
    and it compiled ok, but does not produce the result of clearing all the values from the combo box.

    Again, I appreciate the help! :-)

  5. #5
    Registered User
    Join Date
    May 2004
    Posts
    164
    signing off for the night, will continue and check back in the morning.... for more ideas.

    THanks for the help and happy holidays CProgramming!

  6. #6
    Madly in anger with you
    Join Date
    Nov 2005
    Posts
    211
    have you written the GetCount and DeleteString functions, and if so, do you care to post them for us? the errors you speak of sound rather simple, but that of course depends on the complexity of those 2 functions...

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I'm thinking you are using MFC, perhaps?
    CComboBox has a member function called ResetContent that deletes all items in the combobox.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Registered User
    Join Date
    Dec 2007
    Posts
    214
    ResetContent is what you want, as Elysia stated.

    Also, you shouldn't be calling UpdateData when adding or deleting from a control. For deleting, the controls indexes change as you delete items, so the trick is to start with the largest index and delete down to zero. That way an items index stays the same. I'll bet thats exactly what ResetContent does.

  9. #9
    Registered User
    Join Date
    May 2004
    Posts
    164

    Talking

    You guys ROCK! Thats what I needed. I am using MFC, sorry should have stated that.

    Thanks for the help and the details!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Create new combo boxes based on items selected in preview combo box
    By RealityFusion in forum Windows Programming
    Replies: 2
    Last Post: 01-10-2007, 09:50 AM
  2. disabling user input in a .NET 2.0 Combo box control
    By reanimated in forum Windows Programming
    Replies: 3
    Last Post: 05-01-2006, 06:29 AM
  3. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 06:23 AM
  4. That Dang Activex Microsoft Multimedia 6.0 Control
    By eblack in forum C++ Programming
    Replies: 2
    Last Post: 06-24-2003, 01:39 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM