Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to show the contents of a table selected in ListBox ?

Status
Not open for further replies.

DCMNBD

Technical User
Jan 26, 2005
6
TG
HI,
I m using delphi 5, ADOConnection, ADOTable, DBGrid, ListBox1, DataSource.

I have a database with tables (table1, table2, table3).
To populate the ListBox1 with tables (table1, table2, table3) I wrote the following code:
ADOConnection1.GetTableNames(ListBox1.Items, false); It some how works .

Now I want that when I click on table2(for example in ListBox1) it's contents shows in dbgrid1.

Best Regards.
 
in the listbox click event put something like
Code:
if ADOTable1.Active then ADOTable1.Close;
ADOTable1.TableName := ListBox1.Items[ListBox1.ItemIndex];
ADOTable1.Open;

Aaron Taylor
John Mutch Electronics
 
Not working .....

When I run and I click in the ListBox I get an EstringListError with Index range exceeding limit (-1).

The following is the code :

procedure TFORM1.ListBox1Click(Sender: TObject);
begin

ADOConnection1.GetTableNames(ListBox1.Items, false);
if ADOTable1.Active then ADOTable1.Close;
ADOTable1.TableName := ListBox1.Items[ListBox1.ItemIndex];
ADOTable1.Open;
end;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top