unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, NxGridView6, NxColumns6,
  NxControls6, NxCustomGrid6, NxGrid6, Vcl.ImgList, DateUtils, NxTypes6,
  Vcl.ExtCtrls, NxEdit6, Vcl.Menus, Vcl.Buttons, NxVirtualGrid6;

type
  TForm1 = class(TForm)
    grdMain: TNextGrid6;
    Button1: TButton;
    Edit1: TEdit;
    Button4: TButton;
    gviReport: TNxReportGridView6;
    gviSlides: TNxSlidesGridView6;
    Button5: TButton;
    Button6: TButton;
    NxIncrementColumn61: TNxIncrementColumn6;
    clFirstName: TNxTextColumn6;
    clSallary: TNxNumberColumn6;
    NxCheckBoxColumn61: TNxCheckBoxColumn6;
    NxMemoColumn61: TNxMemoColumn6;
    NxToolbarColumn61: TNxToolbarColumn6;
    NxIconColumn61: TNxIconColumn6;
    ImageList1: TImageList;
    Button9: TButton;
    NxDateColumn61: TNxDateColumn6;
    Button8: TButton;
    NxProgressColumn61: TNxProgressColumn6;
    Label1: TLabel;
    Button11: TButton;
    NxTrackbarColumn61: TNxTrackbarColumn6;
    ImageList2: TImageList;
    Label2: TLabel;
    Edit2: TEdit;
    Button10: TButton;
    Button13: TButton;
    Button15: TButton;
    PopupMenu1: TPopupMenu;
    Report1: TMenuItem;
    Slides1: TMenuItem;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    Panel1: TPanel;
    Button2: TButton;
    Button3: TButton;
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    Button12: TButton;
    Button14: TButton;
    Button7: TButton;
    PopupMenu2: TPopupMenu;
    Delete1: TMenuItem;
    Button16: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure grdMainAcceptEdit(Sender: TObject; ACol, ARow: Integer;
      var Text: WideString; var Accept, CanLeave: Boolean);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure NxToolbarColumn61ButtonClick(Sender: TObject; Index: Integer);
    procedure Button9Click(Sender: TObject);
    procedure grdMainBeforeEdit(Sender: TObject; ACol, ARow: Integer;
      var Accept: Boolean; var Text: WideString);
    procedure Button8Click(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure Button11Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure gviReportGetCellColor(Sender: TObject; ACol, ARow: Integer;
      var CellColor: TColor; State: TNxCellDrawState);
    procedure CheckBox2Click(Sender: TObject);
    procedure Button12Click(Sender: TObject);
    procedure Edit2Change(Sender: TObject);
    procedure Button10Click(Sender: TObject);
    procedure Button13Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure Button15Click(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
    procedure Button14Click(Sender: TObject);
    procedure clFirstNameGetValue(Sender: TObject; ACol, ARow: Integer;
      var Value: WideString);
    procedure grdMainSelect(Sender: TObject; ACol, ARow: Integer);
    procedure grdMainSelectQuery(Sender: TObject; ACol, ARow: Integer;
      var Accept: Boolean);
    procedure grdMainSortQuery(Sender: TObject; Index: Integer;
      SortKind: TNxSortKind; var Accept: Boolean);
  private
    procedure DoButtonClick(Sender: TObject; Index: Integer);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button10Click(Sender: TObject);
begin
  Edit2.Text := '1-20,!15,22,30-35';
end;

procedure TForm1.Button11Click(Sender: TObject);
begin
  gviReport.FixedRowCount := 3;
end;

procedure TForm1.Button12Click(Sender: TObject);
begin
  grdMain.Columns[grdMain.SelectedCol].Hide;
end;

procedure TForm1.Button13Click(Sender: TObject);
begin
  NxDateColumn61.FilterOptions := foToday;
end;

procedure TForm1.Button14Click(Sender: TObject);
var
  Dialog: TSaveDialog;
begin
  Dialog := TSaveDialog.Create(Self);
  try
    if Dialog.Execute then
    begin
      grdMain.Serialize.SaveToCSV(Dialog.FileName);
    end;
  finally
    Dialog.Free;
  end;
end;

procedure TForm1.Button15Click(Sender: TObject);
begin
  grdMain.ScrollBars := [];
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  grdMain.AddRow.Cells.Item[1].AsString := 'Lara';
  grdMain.AddRow.Cells.Item[1].AsString := 'John';
  grdMain.AddRow.Cells.Item[1].AsString := 'Joshua';
  grdMain.AddRow.Cells.Item[1].AsString := 'Michael';
  grdMain.AddRow.Cells.Item[1].AsString := 'Homer';
  grdMain.AddRow.Cells.Item[1].AsString := 'Daniele';
  grdMain.AddRow.Cells.Item[1].AsString := 'Vallery';
  grdMain.AddRow.Cells.Item[1].AsString := 'Julian';
  grdMain.AddRow.Cells.Item[1].AsString := 'George';
  grdMain.AddRow.Cells.Item[1].AsString := 'Ann';
  grdMain.AddRow.Cells.Item[1].AsString := 'Charlie';
  grdMain.AddRow.Cells.Item[1].AsString := 'Jeff';
  grdMain.AddRow.Cells.Item[1].AsString := 'Williams';
  grdMain.AddRow.Cells.Item[1].AsString := 'Lisa';
  grdMain.AddRow.Cells.Item[1].AsString := 'Jenny';
  grdMain.AddRow.Cells.Item[1].AsString := 'Alison';
  grdMain.AddRow.Cells.Item[1].AsString := 'Benjamin';
  grdMain.AddRow.Cells.Item[1].AsString := 'Mickey';
  grdMain.AddRow.Cells.Item[1].AsString := 'Snoopy';
  grdMain.AddRow.Cells.Item[1].AsString := 'Wiliam';
  grdMain.AddRow.Cells.Item[1].AsString := 'Jim';
  grdMain.AddRow.Cells.Item[1].AsString := 'Donald';
  grdMain.AddRow.Cells.Item[1].AsString := 'Wilson';
  grdMain.AddRow.Cells.Item[1].AsString := 'Zack';
  grdMain.AddRow.Cells.Item[1].AsString := 'Phil';

  grdMain.Cell[1, 3].Font.Name := 'Georgia';
  grdMain.Cell[1, 3].Font.Size := 14;
  grdMain.Cell[1, 3].Font.Style := [fsItalic];
  grdMain.Cell[1, 3].Font.Color := $000080FF;

  grdMain.Cell[1, 7].Color := clMoneyGreen;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  grdMain.Row[grdMain.SelectedRow].Visible := False;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  grdMain.UnhideAll;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
  grdMain.Cell[1, grdMain.SelectedRow].AsString := 'Mike';
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
  grdMain.BestFitColumn(grdMain.Columns[grdMain.SelectedCol]);
end;

procedure TForm1.Button6Click(Sender: TObject);
begin
  grdMain.BestFitRow(grdMain.SelectedRow);
end;

procedure TForm1.Button7Click(Sender: TObject);
begin
  if grdMain.Style = vsNative then
  begin
    TButton(Sender).Caption := 'Native UI';
    grdMain.Style := vsModern;
    grdMain.BorderStyle := btSolid;
    grdMain.BorderSize := 0;
  end
  else
  begin
    TButton(Sender).Caption := 'Modern UI';
    grdMain.Style := vsNative;
    grdMain.BorderStyle := btLowered;
    grdMain.BorderSize := 1;
  end;

//ShowMessage(IntToStr(grdMain.Columns.VisibleCount));
end;

procedure TForm1.Button8Click(Sender: TObject);
begin
//  grdMain.MoveRow(5, 2);
  gviReport.FixedColCount := 2;
end;

procedure TForm1.Button9Click(Sender: TObject);
begin
  grdMain.DeleteRow(grdMain.SelectedRow);
end;

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
  grdMain.ActiveView.GridLines := CheckBox1.Checked;
end;

procedure TForm1.CheckBox2Click(Sender: TObject);
begin
  if TCheckBox(Sender).Checked then
    grdMain.AppearanceOptions := grdMain.AppearanceOptions + [aoVisualStyles]
  else
    grdMain.AppearanceOptions := grdMain.AppearanceOptions - [aoVisualStyles];
end;

procedure TForm1.clFirstNameGetValue(Sender: TObject; ACol, ARow: Integer;
  var Value: WideString);
begin
  if Value = 'Ann' then Value := 'Annnnna';
end;

procedure TForm1.DoButtonClick(Sender: TObject; Index: Integer);
begin
  grdMain.Row[grdMain.SelectedRow].Hide;
end;

procedure TForm1.Edit1Change(Sender: TObject);
begin
  clFirstName.Filter := Edit1.Text;
  Caption := 'Showing ' + IntToStr(grdMain.VisibleRowCount) + ' rows';
end;

procedure TForm1.Edit2Change(Sender: TObject);
begin
  clSallary.Filter := Edit2.Text;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  grdMain.Color := clWindow;
//  grdMain.DoubleBuffered := true;
end;

procedure TForm1.grdMainAcceptEdit(Sender: TObject; ACol, ARow: Integer;
  var Text: WideString; var Accept, CanLeave: Boolean);
begin
  if (ACol = 1) and (Text = '') then
  begin
    ShowMessage('OnAcceptEdit event' + #13#10 + 'Block empty entry.' + #13#10 + '--' + #13#10 + 'Accept = False' + #13#10 + 'CanLeave = False' + #13#10 + 'Text = "Enter name"');
    Accept := False;
    CanLeave := False;
    Text := 'Enter name';
  end;
end;

procedure TForm1.grdMainBeforeEdit(Sender: TObject; ACol, ARow: Integer;
  var Accept: Boolean; var Text: WideString);
begin
  if grdMain.Columns[ACol] is TNxDateColumn6 then
  begin
    if Text = DateToStr(0) then
      Text := DateToStr(Today);
  end;
end;

procedure TForm1.grdMainSelect(Sender: TObject; ACol, ARow: Integer);
begin
//  Caption := IntToStr(Random(200));
end;

procedure TForm1.grdMainSelectQuery(Sender: TObject; ACol, ARow: Integer;
  var Accept: Boolean);
begin
  if (ACol = 1) and (ARow = 7) then
  begin
    if MessageDlg('OnSelectQuery event' + #13#10 + '--' + #13#10 + 'Accept = True/False' + #13#10 + 'Do you want to select this cell?', mtConfirmation, mbYesNo, 0) = mrNo then
      Accept := False;
  end;
end;

procedure TForm1.grdMainSortQuery(Sender: TObject; Index: Integer;
  SortKind: TNxSortKind; var Accept: Boolean);
begin
  if SortKind = skAscending then
    Caption := 'Ascending'
  else
    Caption := 'Descending';
end;

procedure TForm1.gviReportGetCellColor(Sender: TObject; ACol, ARow: Integer;
  var CellColor: TColor; State: TNxCellDrawState);
begin
  if not (csSelected in State) then
  begin
    if ARow = -1 then CellColor := $00eeffff;
    if ARow mod 2 = 0 then CellColor := $00fafafa;
  end;
end;

procedure TForm1.NxToolbarColumn61ButtonClick(Sender: TObject; Index: Integer);
begin
  grdMain.Row[grdMain.SelectedRow].Hide;
//  if grdMain.RowExists(ARow) then
//  begin
//    if not (csSelected in State) then
//
//    if ARow mod 2 = 0 then CellColor := $00fcfcfc;
//
//  end;
//NxToolbarColumn61.Items.Add.ImageIndex := 2;
//NxToolbarColumn61.Items[3].Divider := True;
end;

procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
  grdMain.ActiveView := gviReport;
end;

procedure TForm1.SpeedButton2Click(Sender: TObject);
begin
  grdMain.ActiveView := gviSlides;
end;

end.
