Board index » delphi » Adding two seperate items to a ListBox

Adding two seperate items to a ListBox

 I want to write to a Listbox the items from two columns from the table
Trv_Agnc.db:- Trvl_agent_name, City_code.

When I run the query I keep getting the error "Can't find item
'Trvl_agent_name,City_code' when I get to the add to the list section
(see below), any suggestions??

SQLString := 'SELECT Trvl_agent_name,City_code FROM trv_agnc';
   qry := TQuery.Create(Self);
    with qry do
         begin
         DatabaseName:= 'Trvlaudit';
         SQL.Add(SQLString);
         Open();
         end;
    repeat
    lbTrvagent.Items.Add(qry['Trvl_agent_name,City_code']);
    qry.next;
    until qry.eof;
    qry.Free;

I have the list box set-up with two columns & multi select.  Any ideas
on how I can write the selected entries back to another table, only
using the data in column 1, Column 2 is the description of the code in
column 1.

All suggestions greatly appreciated.

regards
Martin

 

Re:Adding two seperate items to a ListBox


Quote
> lbTrvagent.Items.Add(qry['Trvl_agent_name,City_code']);

try

with lbTrvagent.Items do begin
  Add(qry['Trvl_agent_name']);
  Add(qry['City_code']);
end;

or to avoid Variant conversion errors on null values, use:

with lbTrvagent.Items do begin
  Add(qry.fieldByName('Trvl_agent_name').AsString);
  Add(qry.FieldByName(['City_code').AsString);
end;

but you still won't end up with distinct relational columns in a ListBox -
the Columns property in a TListBox determines how many columns are visible
in the control... You want a TListView with ViewStyle = vsReport..

--
David Reed
Diamond Software Group
Oasis Rep Software, Inc
www.diamondsg.com
www.oasisrep.com

Quote
Martin Viant wrote in message <373EBF7E.903A1...@ozemail.com.au>...
> I want to write to a Listbox the items from two columns from the table
>Trv_Agnc.db:- Trvl_agent_name, City_code.

>When I run the query I keep getting the error "Can't find item
>'Trvl_agent_name,City_code' when I get to the add to the list section
>(see below), any suggestions??

>SQLString := 'SELECT Trvl_agent_name,City_code FROM trv_agnc';
>   qry := TQuery.Create(Self);
>    with qry do
>         begin
>         DatabaseName:= 'Trvlaudit';
>         SQL.Add(SQLString);
>         Open();
>         end;
>    repeat
>    lbTrvagent.Items.Add(qry['Trvl_agent_name,City_code']);
>    qry.next;
>    until qry.eof;
>    qry.Free;

>I have the list box set-up with two columns & multi select.  Any ideas
>on how I can write the selected entries back to another table, only
>using the data in column 1, Column 2 is the description of the code in
>column 1.

>All suggestions greatly appreciated.

>regards
>Martin

Re:Adding two seperate items to a ListBox


Quote
>    lbTrvagent.Items.Add(qry['Trvl_agent_name,City_code']);

should be something like

    lbTrvagent.Items.Add(qry.fieldbyName('Trvl_agent_name').asString
     +qry.fieldbyName('City_code').asString);

--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Other Threads