[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Copy Data From DBGrid to ListBox

Posted on 2007-10-11
2
Medium Priority
?
1,193 Views
Last Modified: 2010-04-05
Hi all,

Just another question concerning a DBGrid.

I need to copy all contents of a DBGrid Column Fields to a ListBox.

Anyone know how to do this please?

Thanks again

ST3VO
0
Comment
Question by:ST3VO
2 Comments
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 2000 total points
ID: 20062235
Do you mean, all the fields of the currently selected DBGrid row?

procedure TForm1.Button1Click(Sender: TObject);
var
  i: integer;
begin
  for i := 0 to pred(dbgrid1.FieldCount) do
   listbox1.items.add(dbgrid1.Fields[i].AsString);
end;

Or do you mean all the columns of the currently selected DBGrid ?

procedure TForm1.Button1Click(Sender: TObject);
var
  i: integer;
begin
  for i := 0 to pred(dbgrid1.Columns.Count) do
  // if dbgrid1.Columns[i].Visible then  // Note - Add this if you only wish to include visible columns
   listbox1.items.add(dbgrid1.Columns[i].Field.AsString);
end;

Or do you maen , all the data for 1 particular Grid column, in teh entire dataset ?

procedure TForm1.Button2Click(Sender: TObject);
begin
  CopyDBGridColumnData(2);
end;

procedure TForm1.CopyDBGridColumnData(column: integer);
begin
  DBGrid1.DataSource.DataSet.First;
  while not DBGrid1.DataSource.DataSet.Eof do
  begin
    listbox1.Items.Add(DBGrid1.Columns[column].Field.AsString);
    DBGrid1.DataSource.DataSet.Next;
  end;
end;

0
 

Author Comment

by:ST3VO
ID: 20062358
Brilliant! Thanks :o)
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question