Re: Populating a combo from a database table faster
- From: "Kevin Frevert" <kevin@xxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 29 Mar 2006 14:49:23 -0600
Tom,
One of the database forums might have been a better place for this
question, but this might be an option (if not selecting 20K records isn't an
option)...
{Form show event or some other initialization method}
begin
DataSetToStringList(qMyDataSet,'Description',ComboBox1.Items);
end;
procedure DataSetToStringList(Dataset :TDataSet;
const FieldName :String;
Strings :TStrings);
begin
if (DataSet.Active) and NOT(DataSet.IsEmpty) then
begin
DataSet.DisableControls;
Strings.BeginUpdate; {helps prevent screen/control UI flicker}
try
DataSet.First;
Strings.Clear;
while NOT(DataSet.EOF) do
begin
if Length(FieldName) > 0 then
Strings.Add(DataSet.FieldByName(FieldName).AsString)
else
Strings.Add(DataSet.Fields[0].AsString);
DataSet.Next;
end; { while }
DataSet.First;
finally
Strings.EndUpdate;
DataSet.EnableControls;
end;
end;
end;
{************* End of DataSetToStringList Function
*****************************}
Good luck,
krf
<tglunz@xxxxxxxxxxxxxxxxxxxxx> wrote in message
news:442aef09$1@xxxxxxxxxxxxxxxxxxxxxxxxx
Good afternoon,
I was wondering if anyone know a faster way to populate a combo? In some
cases these combos maybe populated from a query which may return 20,000
records. I am not a fan of populating a combo with that many records, but
it is not my choice. The following code take 7 second to populate the
combo
with 20,000 values:
Combo.items.clear;
CodeQuery.First; // ADO dataset
while CodeQuery.Eof = False do
begin
Combo.Items.Add(CodeQuery.Fields[0].AsString);
CodeQuery.Next;
end;
.
- References:
- Populating a combo from a database table faster
- From: tglunz
- Populating a combo from a database table faster
- Prev by Date: Populating a combo from a database table faster
- Next by Date: Re: Master/detail change problem
- Previous by thread: Populating a combo from a database table faster
- Next by thread: Re: Populating a combo from a database table faster
- Index(es):
Relevant Pages
|