How to load a large array of strings in to an MFC combobox control fast as possible?

后端 未结 5 1625
萌比男神i
萌比男神i 2021-01-06 04:18

I have an array of 1000 strings to load into a combo box. What is the fastest way to load the array of strings into the combo box?

Is there some way other than itera

5条回答
  •  Happy的楠姐
    2021-01-06 05:05

    I had this issue and solved it in two ways, depending on the # items. Setting to not draw and init storage made no difference whatsoever to me. Making an owner draw one is also viable, but I had a ton of comboboxes. Assuming a fixed list for each combobox, that does not change contents, list is set once.

    Very large # Items: Made the combo box just be Simple/Disabled with SetWindowText to set initial string, and a little button next to it opened a dialog that let you choose the item from a list control in Report mode of the data that would've been in the combo box (could be anything done in dialog).

    Moderate # Items: Made a custom derived combobox class that overrides AddString, SelectString, and handles OnDropDown. When you add items, it puts them into a temporary vector, and then on SelectString (could do SetCurSel override too), it adds one item it finds and selects. When dropping down, then it resets the combobox and adds all the items the and selects currently selected one. There is slight slowdown on dropping the combobox, but on low amounts of items is not noticeable.

    It made my dialogs load much faster and still be fully functional without owner draw.

提交回复
热议问题