Re: Populating a combo from a database table faster



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;


.



Relevant Pages

  • RE: Stubborn Array wont Populate from single ADODB.Connection Query
    ... Let UserInfo= RecSet.Fields.Item.Value 'Populate value ... 'Find SQL Server data for the active user. ... ReDim DeptDomainAs String ... Dim Conn As ADODB.Connection 'SQL Server Connection ...
    (microsoft.public.excel.programming)
  • Re: Next DataGridView Question
    ... I also changed ID to PhoneID just to add clarity. ... Public Property PhoneTypeAs String ... Public Property PhoneNumber() As String ... 'populate the objects ...
    (microsoft.public.dotnet.framework.windowsforms.controls)
  • Re: Passing Array of User Defined Type to Form
    ... One, if pmhc is declared in the module, it should use Public, not Dim to declare it. ... You can get away with this for single, simple variable arguments in function/subroutine calls because VB's evaluation of them as an expression is simply themselves. ... teamname As String ... ' Populate the team name fields; ...
    (microsoft.public.excel.programming)
  • Re: Combo box strange ? behavior.
    ... to the FOURTH column of the underlying SQL statement, ... choose the first choice. ... I noticed that when I first choose numeric values to populate the combo ... string values. ...
    (microsoft.public.access.forms)
  • Combo box strange ? behavior.
    ... I have a combobox that its rowsource property is populated with the ... choose the first choice. ... I noticed that when I first choose numeric values to populate the combo ... string values. ...
    (microsoft.public.access.forms)