Hey DT,
There are several ways to do this. You can also use a TDataSource, a TADOConnection and a TADOTable or TADOQuery to connect to a database. You can then either use a data aware TDBComboBox or populate a normal TComboBox using code. (You can also use a TTable, as already mentioned)
I have sent you an example project via e-mail (kit…), since this will be far easier than trying to explain what all the properties need to be set to, or trying to post a project on here. As before, if you have any questions, feel free to ask.
na
McEnroeJ Says
A TCombobox and a TTable.
Attach the TTable to the table in question (eg DatabaseName=DBDEMOS, TableName=items.db) and then to load the combobox (say with OrderNo)
procedure loadcombobox;
var
t_ix_item : integer;
begin
Combobox1.Clear;
Table1.First;
while not table1.eof do
begin
t_ix_item := Combobox1.items.count;
while t_ix_item > 0 do
begin
dec(t_ix_item);
if Combobox1.items.Strings[t_ix_item] = table1['OrderNo'] then
t_ix_item := -1;
end;
if t_ix_item = 0 then
combobox1.Items.Add(table1['OrderNo']);
Table1.Next;
end;
end;
Where all the playing around with t_ix_item is to prevent duplicates from appearing in the combobox. It could be simplified to
procedure loadcombobox;
begin
Combobox1.Clear;
Table1.First;
while not table1.eof do
combobox1.Items.Add(table1['OrderNo']);
Table1.Next;
end;
end;
If you have no duplicates or don’t mind them appearing.
Hey DT,
There are several ways to do this. You can also use a TDataSource, a TADOConnection and a TADOTable or TADOQuery to connect to a database. You can then either use a data aware TDBComboBox or populate a normal TComboBox using code. (You can also use a TTable, as already mentioned)
I have sent you an example project via e-mail (kit…), since this will be far easier than trying to explain what all the properties need to be set to, or trying to post a project on here. As before, if you have any questions, feel free to ask.
na
A TCombobox and a TTable.
Attach the TTable to the table in question (eg DatabaseName=DBDEMOS, TableName=items.db) and then to load the combobox (say with OrderNo)
procedure loadcombobox;
var
t_ix_item : integer;
begin
Combobox1.Clear;
Table1.First;
while not table1.eof do
begin
t_ix_item := Combobox1.items.count;
while t_ix_item > 0 do
begin
dec(t_ix_item);
if Combobox1.items.Strings[t_ix_item] = table1['OrderNo'] then
t_ix_item := -1;
end;
if t_ix_item = 0 then
combobox1.Items.Add(table1['OrderNo']);
Table1.Next;
end;
end;
Where all the playing around with t_ix_item is to prevent duplicates from appearing in the combobox. It could be simplified to
procedure loadcombobox;
begin
Combobox1.Clear;
Table1.First;
while not table1.eof do
combobox1.Items.Add(table1['OrderNo']);
Table1.Next;
end;
end;
If you have no duplicates or don’t mind them appearing.