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 iterating over the list of strings, putting each string into the combo box one at a time?
And how to copy the combo box data once loaded to some 10 other combo boxes?
If you have 1,000 strings repeated in 10 comboboxes, you may want to consider using an owner drawn combobox, which draws the strings on the fly based on indices into your array, rather than storing them in the combobox at all. Way faster, way more memory efficient. Check out the DrawItem method and DRAWITEMSTRUCT structure in the on-line help. Basically, you would do something like using InitStorage and InsertString (as mentioned by NuSonic) to create your 1000 blank items in your combobx, and override DrawItem to extract and draw the required string, based on index, as it needs to be drawn.
I'm not aware of any way to load multiple strings atomically, but there are a couple of things that you can do to make the process more efficient:
Possibly faster than CComboBox with DrawItem would be an owner data CListCtrl. This would also serve your goal of duplicating a subset of the items into other lists, since a common data source could be used.
I suggest this because a 1000-item CComboBox isn't going to be very usable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With