Multiple grids in a scrollable window

I am looking to create multiple grids into a scrollable panel/window.

The example I am trying to implement is similar to ms sql server query ananlyzer when there are multiple record sets generated, these display multilpe grids in a scrollable window.

The number of grids will need to be generated on the fly.

Anyone have any ideas how to do this


thanks

Ian
alchemy9Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

vadim_tiCommented:
procedure someform.somemethod;
begin
  with TDBGrid.Create(Self) do begin
     parent := yourPanel;
    // set wanted grid properties
  end;
end;
0
geobulCommented:
Hi,

A possible solution is to use one TScrollBox component as a parent of your grids. Create it on the form and set grids parent properties to that box. If you need code, let me know.

Regards, Geo
0
esoftbgCommented:
Or TPageControl with many TTabSheets containing DBGrids .... You will not scroll, but browse between TabSheets ....
0
esoftbgCommented:
download a full example from:
page:        http://www.geocities.com/esoftbg/
  link:        Q_21178629.zip

unit Unit1_Q_21178629;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics,
  Controls, Forms, Dialogs, DB, DBTables, Grids, DBGrids,
  Buttons, StdCtrls, ExtCtrls, DBCtrls, ComObj, ADODB, ToolWin, ComCtrls,
  Spin, Calendar;

type
  TForm1 = class(TForm)
    ToolBar: TToolBar;
    ADOConnection: TADOConnection;
    ListBoxTables: TListBox;
    PageControl: TPageControl;
    tbtnShowTable: TToolButton;
    tbtnDatabase: TToolButton;
    ADOCommand: TADOCommand;
    tbtnDeletePage: TToolButton;
    procedure FormCreate(Sender: TObject);
    procedure tbtnShowTableClick(Sender: TObject);
    procedure PageControlChange(Sender: TObject);
    procedure tbtnDatabaseClick(Sender: TObject);
    procedure ListBoxTablesClick(Sender: TObject);
    procedure tbtnDeletePageClick(Sender: TObject);
    procedure ListBoxTablesDblClick(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private   { Private declarations }
    ConnStr:  string;
  public    { Public declarations }
    function  OpenAccessDB(FN: string): Boolean;
  end;

var
  Form1: TForm1;

implementation

uses
  Unit2_Q_21178629;

{$R *.dfm}

function  TForm1.OpenAccessDB(FN: string): Boolean;
var
  B:      Boolean;
  T:      string;
  V:      Variant;
  SL:     TStringList;
  function  CreateAccessTable(TableName: string; Fields: string): Boolean;
  begin
    Result := True;
    try
      ADOCommand.Connection := AdoConnection;
      T :=' Create Table ' + TableName
        + ' ( ' + Fields + ' )';
      ADOCommand.CommandText := T;
      ADOCommand.Execute;
    except
      Result := False;
    end;
  end;
begin
  B := True;
  try
    try
      ConnStr := 'Data Source=' + FN + ';Provider=Microsoft.Jet.OLEDB.4.0';
      if not FileExists(FN) then
      begin
        V := CreateOleObject('ADOX.Catalog');
        V.Create(ConnStr);
      end;
      ADOConnection.Connected := False;
      ADOConnection.ConnectionString := ConnStr;
      ADOConnection.Open;
      SL := TStringList.Create;
      try
        AdoConnection.GetTableNames(SL);
      finally
        ListBoxTables.Items.Assign(SL);
        if (ListBoxTables.Items.Count>0) then
          ListBoxTables.ItemIndex := 0;
        SL.Free;
      end;
    except
      B := False;
    end;
  finally
    Result := B;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  FN:     string;
begin
  FN := ExtractFilePath(Application.ExeName) + 'DATABASE.MDB';
  OpenAccessDB(FN);
end;

procedure TForm1.tbtnShowTableClick(Sender: TObject);
var
  B:      Boolean;
  I:      Integer;
  Idx:    Integer;
  SL:     TStringList;
  S:      string;
  T:      string;
  Bar:    TPanel; // TToolBar;
  ADOQ:   TADOQuery;
  DBG:    TDBGrid;
  DBN:    TDBNavigator;
  DSA:    TDataSource;
  Sheet:  TTabSheet;
  ListBox:TListBox;
begin
  Idx := 0;
  if (ListBoxTables.Items.Count>0) then
  if (ListBoxTables.ItemIndex>-1) then
  begin
    B := True;
    S := ListBoxTables.Items[ListBoxTables.ItemIndex];
    for I := 0 to PageControl.PageCount-1 do
    begin
      if (PageControl.Pages[I].Caption=S) then
      begin
        Idx := ListBoxTables.ItemIndex;
        B := False;
        Break;
      end;
    end;
    if B then
    begin
      Idx := PageControl.PageCount;
      Sheet := TTabSheet.Create(PageControl);
      Sheet.PageControl := PageControl;
      Sheet.Caption := S;
      ListBox := TListBox.Create(Sheet);
      ListBox.Parent := Sheet;
      SL := TStringList.Create;
      try
        Bar := TPanel.Create(Sheet);
        Bar.Parent := Sheet;
        ADOQ := TADOQuery.Create(Sheet);
        AdoConnection.GetFieldNames(S, SL);
        ListBox.Items.Assign(SL);
        ADOQ.Connection := AdoConnection;
        T :=''
          + ' SELECT * FROM ' + S
          + '';
        ADOQ.SQL.Text := T;
        DSA := TDataSource.Create(Sheet);
        DSA.DataSet := ADOQ;
        DBG := TDBGrid.Create(Sheet);
        DBG.Parent := Sheet;
        DBG.DataSource := DSA;
        DBN := TDBNavigator.Create(Sheet);
        DBN.Parent := Sheet;
        DBN.DataSource := DSA;
        DBG.Height := 256;
        DBG.Align := alTop;
        ListBox.Align := alClient;
        Bar.Height := 26;
        Bar.Align := alTop;
        Bar.Visible := True;
        ADOQ.Active := True;
      finally
        SL.Free;
      end;
    end;
    PageControl.ActivePageIndex := Idx;
  end;
end;

procedure TForm1.ListBoxTablesDblClick(Sender: TObject);
begin
  tbtnShowTableClick(Sender);
end;

procedure TForm1.PageControlChange(Sender: TObject);
var
  I:      Integer;
  S:      string;
begin
  S := PageControl.Pages[PageControl.ActivePageIndex].Caption; // ;
  for I := 0 to PageControl.PageCount-1 do
  begin
    if (ListBoxTables.Items[I]=S) then
    begin
      ListBoxTables.ItemIndex := I;
      Break;
    end;
  end;
end;

procedure TForm1.ListBoxTablesClick(Sender: TObject);
var
  I:      Integer;
  S:      string;
begin
  S := ListBoxTables.Items[ListBoxTables.ItemIndex];
  for I := 0 to PageControl.PageCount-1 do
  begin
    if (PageControl.Pages[I].Caption=S) then
    begin
      PageControl.ActivePageIndex := I;
      Break;
    end;
  end;
end;

procedure TForm1.tbtnDatabaseClick(Sender: TObject);
begin
  Form2.ShowModal;
end;

procedure TForm1.tbtnDeletePageClick(Sender: TObject);
var
  I:      Integer;
begin
  if PageControl.ActivePageIndex>=0 then
  try
    for I := ComponentCount-1 downto 0 do
    begin
      if (Components[I] is TADOQuery) then
      begin
        if ((Components[I] as TADOQuery).Owner=PageControl.Pages[PageControl.ActivePageIndex]) then
        begin
          (Components[I] as TADOQuery).Active := False;
          (Components[I] as TADOQuery).Destroy;
        end;
      end
      else
      if (Components[I] is TControl) then
        if ((Components[I] as TControl).Parent=PageControl.Pages[PageControl.ActivePageIndex]) then
          (Components[I] as TControl).Destroy;
    end;
  finally
    PageControl.Pages[PageControl.ActivePageIndex].Destroy;
  end;
end;

procedure TForm1.FormDestroy(Sender: TObject);
var
  I:      Integer;
begin
  try
    for I := 0 to ADOConnection.DataSetCount-1 do
      ADOConnection.DataSets[I].Active := False;
  finally
    with PageControl do
    begin
      while (PageCount>0) do
      try
        for I := ComponentCount-1 downto 0 do
        begin
          if (Components[I] is TControl) then
            if ((Components[I] as TControl).Parent=Pages[PageCount-1]) then
              (Components[I] as TControl).Destroy;
        end;
      finally
        Pages[PageCount-1].Destroy;
      end;
    end;
  end;
end;

end.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.