Thread: Combo Box in MFC, how to randomize data of it...please help!

  1. #1
    Unregistered
    Guest

    Lightbulb Combo Box in MFC, how to randomize data of it...please help!

    I have a combo box (MFC) that have 3 data entries in it.

    Lets say they are...

    data1
    data2
    data3

    How do I make it so that when i press a button, the data randomize and display? Please help.

  2. #2
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    First make sure the Sort property of the ComboBox is turned off.

    And the rest.... there must be a simpler way to do this but I'll give it a try:

    Code:
    int nofItems = 0;
    int len = 0;  // item length
    int randIndex = 0; // index to item (random)
    char item[1024];
    
    nofItems = Box.GetCount();
    
    srand(time(NULL));
    
    for(int i = 0; i < nofItems; i++) 
    {	
      randIndex = rand() % nofItems;  // pick random item
      len = Box.GetLBTextLen(randIndex);  // get length of string
      Box.GetLBText(randIndex, item);  // save string 
      Box.DeleteString(randIndex);  // delete string from list	
      Box.AddString(item);  // add string at end of list
    }

  3. #3
    Unregistered
    Guest

    Lightbulb Thank you...but...

    Thank you for replying, but I'm still unclear about this. I assumed that "Box" is my combobox, but my combobox control name is IDC_COMBOTEST, how do I tell the name of my box?

  4. #4
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    In VC++ 6.0:

    Open ClassWizzard: View -> ClassWizzard (or CTRL+W)
    Select tab "Member Variables"
    Select your control ID (IDC_COMBOTEST)
    Press button "Add variable..."
    Enter the name of the member variable (m_DialogBox)
    Category: Control (not String)
    Variable type: CComboBox
    Press "OK"

    Now you have added a new variable called m_DialoxBox.
    You can use this variable to update the Dialog Box.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reset Combo Control VS C++ 6.0
    By WaterNut in forum Windows Programming
    Replies: 8
    Last Post: 12-26-2007, 10:37 AM
  2. 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
  3. WIndows programming?
    By hostensteffa in forum Windows Programming
    Replies: 7
    Last Post: 06-07-2002, 08:52 PM
  4. Combo Box Extended
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 11-15-2001, 09:04 AM
  5. list box in mfc, get data from file
    By davebaggott in forum Windows Programming
    Replies: 9
    Last Post: 10-08-2001, 04:45 PM