best way to populate multiple combo boxes efficiently??

ggc
10-20-2004, 07:25 AM
Hi everyone,

I have a form which is going to act as a "bulk entry" sheet for the daily work statistics of the users of my application.

It contains a picture box containing a row of controls which repeats 50 times. One of the controls is the "action" box which will be a combobox populated from a database table. Whenever I have used comboboxes like this in the past I have always populated them in the dropdown event. However as this control is repeated and the drop down action is therefore potentially repeated 50 times, it surely doesnt make sense to hit the db and populate the combo for each instance of the control that is used does it??

Can anyone suggest a more efficient/better practice way of doing this please. Should I be considering something like a disconnected recordset (I'd then only hit the db once and the data to populate each instance of the action control would already be there) or is there an even better way to do this ???

Shurik12
10-20-2004, 07:51 AM
Hi,

Just a question (if I understand your question correctly), have you overweighed using a grid (MSFlexGrid,MSHFlexGrid, DataGrid...) instead?

Shurik.

noi_max
10-20-2004, 07:52 AM
Hi everyone,

I have a form which is going to act as a "bulk entry" sheet for the daily work statistics of the users of my application.

It contains a picture box containing a row of controls which repeats 50 times. One of the controls is the "action" box which will be a combobox populated from a database table. Whenever I have used comboboxes like this in the past I have always populated them in the dropdown event. However as this control is repeated and the drop down action is therefore potentially repeated 50 times, it surely doesnt make sense to hit the db and populate the combo for each instance of the control that is used does it??

Can anyone suggest a more efficient/better practice way of doing this please. Should I be considering something like a disconnected recordset (I'd then only hit the db once and the data to populate each instance of the action control would already be there) or is there an even better way to do this ???

Controls X 50?? That's a heck of an interface!
In the past, I have populated comboboxes or listboxes in a Form_Load or Form_Activate event.
Basically the program makes a call to the database, fills the comboboxes and then disconnects, as you said.
If the data changes, and you need the combobox updated, you can always clear the combobox and reload it as needed.

If you must have 50 comboboxes, consider using a control array. That way you can use a nested loop to load the values from the db.

something like... (in pseudo)

Open recordset

For i = Combo1.Lbound To Combo1.Ubound
MoveFirst
Do While Not Record.EOF
Combo1(i).AddItem myRecord
MoveNext
Loop
Next i

Close recordset

Again, that's just psuedocode.

Hope it's at least a little helpful.

Shurik12's suggestion is better... ;) A grid would make data entry like this a lot easier for the user, and hopefully for you too.

ggc
10-20-2004, 08:04 AM
Shurik, I hadnt considered flexgrids, mainly because ive never used them before and what i am achieving with my code has been done in a similar way on another form by a different programmer on the project so I nicked it (dont need to re-invent the wheel eh ?? ;) )

Noi max: As I said it is a bulk data entry form. I have not created all 50 rows at design time, only one row. The rest are created at run time and are in a frame controlled by a scroll bar so you only see 10 at a time, if the other 40 aren't required then its no biggy. All 50 lines arent visible at once !!!


As for the code you posted, yeah thats what i normally do, but my point is that if the user creates 50 lines to be saved away to the db, they are therefore clicking the action drop down 50 times and I am getting the same recordset 50 times. This seems silly and i wondered if disconnected recordset would be better or if there is some other fantastic time saving way i could do this without creating loads of unnecessary database hits.

ggc
10-20-2004, 08:16 AM
I have attached my form hope this helps explain things a little better :)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum