TAdvStringGrid

Example 71 : Using the TAdvGridImportDialog

vcl grid

If you want to allow that users open different kinds of CSV or TXT files with TAdvStringGrid, it is often troublesome to know what column delimiter is being used in a CSV file and it is even more complicated to know column positions in TXT files with fixed columns. Through the TAdvGridImportDialog, it is possible to show users a preview of the import with a choosen delimiter or to set the column positions for fixed column width TXT files. 

To use TAdvGridImportDialog, drop an instance of TAdvGridImportDialog on the form, set the Grid property to the grid you want to use the import dialog for and call either AdvGridImportDialog.Execute or AdvGridImportDialog.OpenAndExecute.

When calling AdvGridImportDialog1.OpenAndExecute, first a File Open dialog is shown to allow to select the CSV or TXT file and then the preview for the import is shown. If you do not want the File Open dialog to appear, set the filename to open with AdvGridImportDialog1.FileName and call AdvGridImportDialog1.Execute.

At runtime, either the delimiter can be choosen or the column positions can be indicated by clicking in the header. The column position indicator pins can be selected and moved in the header and can be removed again by dragging the pins outside the header.

After pressing OK, the choosen settings are applied to load the CSV or TXT file in the associated grid set with AdvGridImportDialog.Grid.

Delphi project & source files for downloading included in the main demos distribution for Delphi.