[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Multiple grids in a scrollable window

Posted on 2004-10-22
7
Medium Priority
?
195 Views
Last Modified: 2010-04-05
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
0
Comment
Question by:alchemy9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
7 Comments
 
LVL 6

Expert Comment

by:vadim_ti
ID: 12380402
procedure someform.somemethod;
begin
  with TDBGrid.Create(Self) do begin
     parent := yourPanel;
    // set wanted grid properties
  end;
end;
0
 
LVL 17

Expert Comment

by:geobul
ID: 12381033
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
 
LVL 12

Expert Comment

by:esoftbg
ID: 12381898
Or TPageControl with many TTabSheets containing DBGrids .... You will not scroll, but browse between TabSheets ....
0
 
LVL 12

Accepted Solution

by:
esoftbg earned 2000 total points
ID: 12382229
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

650 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