Using TAdvGridImportDialog to load large CSV file

When I load a file with say 10,000 lines and a dozen columns, it takes a few seconds and the GUI freezes.

I would like to show a progress bar or use the TMSFNCWaitingIndicator to let the user know the file is loading..

I notice that TAdvStringGrid.OpenAndExecute can load the file pretty fast, and my progress bar completes, but

  1. the ImportDialog stays on screen until the grid refreshes
  2. for 10,000 rows, 12 columns, the grid takes 10x longer loading to refresh on screen than to load from CSV.
  3. so using OnFileProgress with a ProgressBar would show completed, the GUI hangs while waiting for the Grid to refresh with the data

Question: Assuming I really want to load ALL the data, what is the recommendation to let the user know to be have patience? :rofl:smile:

The idea scenario I think would be that ImportDialog should close, and then show a progress box that takes into account the CSV file loading AND grid population of data and refresh timing...

Is there a similar Event I can use in TAdvStringgrid to show the latter?

procedure TForm1.ActionLoadDataExecute(Sender: TObject);
begin
  CodeSite.EnterMethod( 'ActionLoadDataExecute' );

  AdvGrid1.BeginUpdate;
  try
    // select file and import
    CodeSite.Send( 'Before OpenAndExecute' );

    if AdvGridImportDialog1.OpenAndExecute then
    begin
      CodeSite.Send( 'After OpenAndExecute' );
      // is the first row headers? if yes
      if AdvGridImportDialog1.FirstRowHeaders = False then
        AdvGrid1.InsertRows(1, 0);
      CodeSite.Send( 'After InsertRows' );
      // Add S.No to the 0 column in the grid.
      AdvGrid1.InsertCols(0,1);
      AdvGrid1.AutoNumberCol(0);
      AdvGrid1.AutoFitColumns;
      CodeSite.Send( 'After InsertCols' );
    end;
  finally
    CodeSite.Send( 'Before EndUpdate' );
    AdvGrid1.EndUpdate;
    CodeSite.Send( 'After EndUpdate' );
  end;
  CodeSite.ExitMethod( 'ActionLoadDataExecute' );
end;
procedure TForm1.AdvGrid1FileProgress(Sender: TObject; progress: SmallInt);
begin
  AdvProgressBar1.Position := progress;
end;

We have added an event OnFileProgress at TAdvGridImportDialog level.
This event will be available in the next update.

1 Like

Thank you!