Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a table
CREATE TABLE [main](
    [ID] INTEGER PRIMARY KEY AUTOINCREMENT, 
    [Name] TEXT, 
    [Address] VARCHAR, 
    [Phone] VARCHAR, 
    [E-Mail] VARCHAR, 
    [Vin] INTEGER, 
    [Year] VARCHAR, 
    [Make] VARCHAR, 
    [Model] VARCHAR, 
    [Job Hours] FLOAT, 
    [Pictures] GRAPHIC, 
    [Repair Order Number] INT, 
    [Purchase Order Number] INT, 
    [RO Description] VARCHAR);


I want to display all the columns in my database in my listbox2.

What I have tried:

I have tried this code but it only loads the Name column ;
I do see 2 other blank items below the name column
<pre lang="Delphi">begin
  AccessCameraAppForm.fdloadmainToListbox.Close;
  // AccessCameraAppForm.fdloadmainToListbox.SQL.Text := 'SELECT site FROM uyeler ORDER BY site';
  try
    AccessCameraAppForm.fdloadmainToListbox.Open;
    AccessCameraAppForm.ListBox2.Items.Clear;
    while not AccessCameraAppForm.fdloadmainToListbox.Eof do
    begin
      AccessCameraAppForm.ListBox2.Items.Add
        (AccessCameraAppForm.fdloadmainToListbox.Fields[0].AsString);
        AccessCameraAppForm.ListBox2.Items.Add
        (AccessCameraAppForm.fdloadmainToListbox.Fields[1].AsString);
        AccessCameraAppForm.ListBox2.Items.Add
        (AccessCameraAppForm.fdloadmainToListbox.Fields[2].AsString);
      AccessCameraAppForm.fdloadmainToListbox.Next;
    end;
  finally
    AccessCameraAppForm.fdloadmainToListbox.Close;
  end;
Posted
Updated 1-Feb-19 17:25pm
v2

You are adding extra items instead of passing the stuff as columns.

See this example SwissDelphiCenter.ch : ...show Columns in a TListBox using Tabulators of different widths?[^]
Once you have set up your tabulators you should be adding your data like this:
Delphi
AccessCameraAppForm.ListBox2.Items.Add (AccessCameraAppForm.fdloadmainToListbox.Fields[1].AsString Tab + AccessCameraAppForm.fdloadmainToListbox.Fields[1].AsString + Tab + AccessCameraAppForm.fdloadmainToListbox.Fields[2].AsString);


Edit.
Based on your comment below and the sample query in the comment in your code, you are not using the correct query to extract data from the database. Try something like this
select [ID], [Name], [Address], [Phone], [E-Mail], [Vin], [Year], [Make], [Model], [Job Hours], [Repair Order Number], [Purchase Order Number], [RO Description]
From main
Note, I've omitted the graphics column
 
Share this answer
 
v2
Comments
[no name] 1-Feb-19 12:50pm    
Wow! +5
CHill60 1-Feb-19 13:06pm    
A blast from my past :-)
Thanks for your help.
I do not need to add columns to the list box.

I need to add all the information from my database e to to the listbox
So no columns in the list box. Just the data . This is a android app so the listbox will scroll.
 
Share this answer
 
v2
Comments
CHill60 1-Feb-19 22:58pm    
You said you wanted to add columns to your listbox. Quote: " want to displat all the columns in my listbox2." I explained how to do that.
Now you have accepted your own comment as a solution .. so no-one will bother to help you further because your post has an accepted answer.. you're on your own now
grantfullen 1-Feb-19 23:21pm    
Not use to this site. I did Undo the accept.
If you look at the title of the question . Fill listbox with all database columns.
Sorry for the confusion.
CHill60 3-Feb-19 5:35am    
I've updated my solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900