Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9162193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:09:09+00:00 2026-06-17T14:09:09+00:00

I have a DB grid which is sorted (the user clicked a few radio

  • 0

I have a DB grid which is sorted (the user clicked a few radio buttons and checkboxes to influence the display).

I would like to export all of the data (not just what is visible in the grid), sorted identically, to CSV – how do I do so? The data – not the user settings, just to clarify.

Thanks in advance for any help


[Update] I build sqlQuery bit by bit, depending on the user’s settings of checkboxes & radio groups, then, when one of them changes, I

   ActivityADQuery.SQL.Clear();
   ActivityADQuery.SQL.Add(sqlQuery);
   ActivityADQuery.Open(sqlQuery);

That is to say that there isn’t a hard coded query, it varies and I want to export the current settings.

I don’t know enough if I want to export from the grid or the dataset (I am just not a db guy, this is my first DBgrid), but I suspect that I want the grid, because it has a subset of fields of he dataset.

I guess that TJvDBGridCSVExport is a Jedi component(?) I have tried to avoid them so far, great as they sound, because I prefer discreet, stand-alone, components to installing a huge collection. That may not be the cleverest thing to do, but it’s how I feel – ymmv (and prolly does)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T14:09:11+00:00Added an answer on June 17, 2026 at 2:09 pm

    Another solution, works also with (multi)selected rows:

    procedure TReportsForm.ExportToCSV(const aGrid : TDBGrid; const FileName : String);
    Var
      I, J : Integer;
      SavePlace : TBookmark;
      Table : TStrings;
      HeadTable : String;
      LineTable : String;
      First : Boolean;
    Begin
    
      HeadTable := '';
      LineTable := '';
      Table := TStringList.Create;
      First := True;
    
      Try
        For I := 0 To Pred(aGrid.Columns.Count) Do
          If aGrid.Columns[I].Visible Then
            If First Then
            Begin
    // Use the text from the grid, in case it has been set programatically
    // E.g., we prefer to show "Date/time" than "from_unixtime(activity.time_stamp, "%D %b %Y  %l:%i:%S")"
    //          HeadTable := HeadTable + aGrid.Columns[I].FieldName;
              HeadTable := HeadTable + ActivityReportStringGrid.Columns[i].Title.Caption + ','; // Previous separated wth semi-colon, not comma! (global)
              First := False;
            End
            Else
            begin
    //          HeadTable := HeadTable + ';' + aGrid.Columns[I].FieldName;
              HeadTable := HeadTable + ActivityReportStringGrid.Columns[i].Title.Caption + ',';
            end;
    
        Delete(HeadTable, Length(HeadTable), 1);  // Remove the superfluous trailing comma
        Table.Add(HeadTable);
        First := True;
    
        // with selection of rows
        If aGrid.SelectedRows.Count > 0 Then
        Begin
          For i := 0 To aGrid.SelectedRows.Count - 1 Do
          Begin
            aGrid.DataSource.Dataset.GotoBookmark(pointer(aGrid.SelectedRows.Items[i]));
            For j := 0 To aGrid.Columns.Count - 1 Do
              If aGrid.Columns[J].Visible Then
                If First Then
                Begin
                  lineTable := lineTable + aGrid.Fields[J].AsString;
                  First := False;
                End
                Else
                  lineTable := lineTable + ',' + aGrid.Fields[J].AsString;
    
            Delete(LineTable, Length(LineTable), 1);  // Remove the superfluous trailing comma
            Table.Add(LineTable);
            LineTable := '';
            First := True;
          End;
        End
        Else
          //no selection
        Begin
          SavePlace := aGrid.DataSource.Dataset.GetBookmark;
          aGrid.DataSource.Dataset.First;
    
          Try
            While Not aGrid.DataSource.Dataset.Eof Do
            Begin
              For I := 0 To aGrid.Columns.Count - 1 Do
                If aGrid.Columns[I].Visible Then
                  If First Then
                  Begin
                    lineTable := lineTable + aGrid.Fields[I].AsString;
                    First := False;
                  End
                  Else
                    lineTable := lineTable + ',' + aGrid.Fields[I].AsString;
    
    
              Delete(LineTable, Length(LineTable), 1);  // Remove the superfluous trailing comma
              Table.Add(LineTable);
              LineTable := '';
              aGrid.DataSource.Dataset.Next;
              First := True;
            End;
    
            aGrid.DataSource.Dataset.GotoBookmark(SavePlace);
          Finally
            aGrid.DataSource.Dataset.FreeBookmark(SavePlace);
          End;
        End;
        Table.SaveToFile(FileName);
      Finally
        Table.Free;
      End;
    End;  // ExportToCSV()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a grid which I would like to show extra information with RowExpander
I have grid view which contains five radio buttons per row. Out of these
I have a grid which shows product versions and have a few link buttons
I have a Telerik Grid which has a footer that needs to display column
I have a Grid which shows a layout for an invoice. What I would
I have a grid in which file names are displayed as link buttons. But
I'd like to have a dojo grid which connects to a server url which
Hi I have a grid which used to display call details. It is displaying
I have a grid which has 4 bands and the columns in band[3] are
I have a Grid which contains an Image in one of its columns. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.