unit GridsInGrid;

interface

uses
  Classes, SysUtils, IWAppForm, IWApplication, IWTypes, IWAdvWebGrid,
  IWTMSCtrls, IWCompListbox, IWWebGrid, IWCompLabel, Controls,
  IWBaseControl, IWControl, IWCompButton, LeftFrame, Forms, TopFrame,
  IWVCLBaseControl, IWBaseHTMLControl;

type
  TformGridsInGrid = class(TIWAppForm)
    IWButton1: TIWButton;
    IWButton2: TIWButton;
    IWButton3: TIWButton;
    IWLabel1: TIWLabel;
    TIWAdvWebGrid1: TTIWAdvWebGrid;
    IWButton4: TIWButton;
    IWListbox1: TIWListbox;
    IWListbox2: TIWListbox;
    IWLabel2: TIWLabel;
    TIWClientCode1: TTIWClientCode;
    TIWAdvDetailWebGrid1: TTIWAdvDetailWebGrid;
    TIWAdvDetailWebGrid2: TTIWAdvDetailWebGrid;
    FrameTopFrame1: TFrameTopFrame;
    FrameLeftFrame1: TFrameLeftFrame;
    procedure IWButton1Click(Sender: TObject);
    procedure IWButton2Click(Sender: TObject);
    procedure IWButton3Click(Sender: TObject);
    procedure IWButton4Click(Sender: TObject);
    procedure TIWAdvWebGrid1AfterGotoLink(Sender: TObject; RowIndex,
      ColumnIndex: Integer);
    procedure TIWAdvWebGrid1GetCellDetail(Sender: TObject; RowIndex,
      ColumnIndex: Integer; var AValue: String);
    procedure TIWAdvWebGrid1GetDetailGrid(Sender: TObject;
      RowIndex: Integer; var AGrid: TTIWCustomWebGrid);
    procedure IWAppFormCreate(Sender: TObject);
  public
  end;

implementation

{$R *.dfm}

uses
  ServerController;


procedure TformGridsInGrid.IWButton1Click(Sender: TObject);
begin
  TIWAdvWebGrid1.Edit;
end;

procedure TformGridsInGrid.IWButton2Click(Sender: TObject);
begin
  TIWAdvWebGrid1.Post;
end;

procedure TformGridsInGrid.IWButton3Click(Sender: TObject);
var
  i: Integer;
begin
  iwlistbox1.Items.Clear;
  with TIWAdvDetailWebGrid1 do
    for i := 1 to TotalRows do
      iwlistbox1.items.Add(Cells[1,i-1]+':'+DynEdits[3,i-1]);
end;

procedure TformGridsInGrid.IWButton4Click(Sender: TObject);
var
  i: Integer;
begin
  iwlistbox2.Items.Clear;
  with TIWAdvDetailWebGrid2 do
    for i := 1 to TotalRows do
      iwlistbox2.items.Add(Cells[1,i-1]+':'+DynEdits[3,i-1]);
end;

procedure TformGridsInGrid.TIWAdvWebGrid1AfterGotoLink(Sender: TObject; RowIndex,
  ColumnIndex: Integer);
begin
  TiwAdvWebGrid1.Edit;
end;

procedure TformGridsInGrid.TIWAdvWebGrid1GetCellDetail(Sender: TObject; RowIndex,
  ColumnIndex: Integer; var AValue: String);
begin
  AValue := 'This is the detail for row ' + IntToStr(RowIndex + TIWAdvWebGrid1.RowOffset);
end;

procedure TformGridsInGrid.TIWAdvWebGrid1GetDetailGrid(Sender: TObject;
  RowIndex: Integer; var AGrid: TTIWCustomWebGrid);
begin
  // only show a detail row for rows 0 & 1
  AGrid := nil;
  case RowIndex + TIWAdvWebGrid1.RowOffset of
  0:AGrid := TIWAdvDetailWebGrid1;
  1:AGrid := TIWAdvDetailWebGrid2;
  end;
end;

procedure TformGridsInGrid.IWAppFormCreate(Sender: TObject);
var
  i: Integer;
begin
  // loads the grid from a CSV file and inserts a node column
  tiwadvwebgrid1.LoadFromCSV(WebApplication.ApplicationPath + 'cars.csv');

  for i := 1 to tiwadvwebgrid1.Columns.Count do
    tiwadvwebgrid1.Columns[i - 1].Width := 72;

  tiwadvwebgrid1.Columns[0].Width := 160;

  tiwadvwebgrid1.InsertColumns(0,1);

  tiwadvwebgrid1.columns.Insert(0).ColumnType := ctNode;
  tiwadvwebgrid1.Columns[0].Width := 40;
  // presets the rows 0 o have detail row open
  tiwadvwebgrid1.DetailStates[0] := true;

  // initialize detailgrids
  with TIWAdvDetailWebGrid1 do
  begin
    RowCount := 5;
    TotalRows := 5;
    Cells[1,0] := 'BMW';
    Cells[2,0] := 'Z3';
    Cells[1,1] := 'Audi';
    Cells[2,1] := 'A4';
    Cells[1,2] := 'Porsche';
    Cells[2,2] := '911';
    Cells[1,3] := 'Ferrari';
    Cells[2,3] := 'F550';
    Cells[1,4] := 'Mercedes';
    Cells[2,4] := 'CL600';
    Columns[1].Title := 'Car';
    Columns[2].Title := 'Type';
    Columns[2].FooterText := '<B>Total</B>';
    Columns[3].Title := 'Quantity';

  end;

  with TIWAdvDetailWebGrid2 do
  begin
    RowCount := 3;
    TotalRows := 3;
    Cells[1,0] := 'Mercedes';
    Cells[2,0] := 'SL500';
    Cells[1,1] := 'Ferrari';
    Cells[2,1] := 'F355';
    Cells[1,2] := 'Porsche';
    Cells[2,2] := 'Carrera';
    Columns[1].Title := 'Car';
    Columns[2].Title := 'Type';
    Columns[2].FooterText := '<B>Total</B>';
    Columns[3].Title := 'Quantity';
  end;
end;

initialization
  TformGridsInGrid.SetAsMainForm



end.
