unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Menus, Grids, ImgList, ComCtrls, ToolWin, CheckLst, ExtCtrls,
  Buttons, DateUtils,
  NxGridPrint, NxColumnClasses, NxColumns, NxScrollControl, NxCustomGridControl,
  NxCustomGrid, NxGrid, NxEdit, NxSharedCommon, NxClasses;

type
  TForm1 = class(TForm)
    NextGrid1: TNextGrid;
    ImageList2: TImageList;
    imlGrid: TImageList;
    MainMenu1: TMainMenu;
    Action1: TMenuItem;
    InsertColumn31: TMenuItem;
    DeleteColumn21: TMenuItem;
    DeleteSelectedRow1: TMenuItem;
    Cells12Test1: TMenuItem;
    AddRow201: TMenuItem;
    SaveDialog1: TSaveDialog;
    EditCell261: TMenuItem;
    SaveDialog2: TSaveDialog;
    OpenDialog1: TOpenDialog;
    NormalImageList: TImageList;
    CoolBar1: TCoolBar;
    ToolBar2: TToolBar;
    btnLeftAlignment: TToolButton;
    btnCenterAlignment: TToolButton;
    btnRightAlignment: TToolButton;
    ToolButton6: TToolButton;
    ToolButton3: TToolButton;
    ToolButton4: TToolButton;
    ToolButton5: TToolButton;
    ToolButton7: TToolButton;
    btnAddRow: TToolButton;
    btnAddCol: TToolButton;
    ToolButton10: TToolButton;
    ToolButton13: TToolButton;
    ToolButton12: TToolButton;
    ToolButton14: TToolButton;
    ToolButton16: TToolButton;
    ToolButton15: TToolButton;
    ToolButton8: TToolButton;
    ToolButton17: TToolButton;
    ToolButton20: TToolButton;
    ToolButton18: TToolButton;
    ToolButton19: TToolButton;
    ToolButton9: TToolButton;
    ToolButton21: TToolButton;
    ToolButton22: TToolButton;
    GridPrint1: TNxGridPrint;
    PrintDialog1: TPrintDialog;
    Columns2SortedTrue1: TMenuItem;
    Cell24ColorclRed1: TMenuItem;
    Actions1: TMenuItem;
    urnOnAutoSize1: TMenuItem;
    SaveSettingsToINIFile1: TMenuItem;
    N1: TMenuItem;
    LoadSettingsFromINIFile1: TMenuItem;
    N2: TMenuItem;
    Print1: TMenuItem;
    N3: TMenuItem;
    Exit1: TMenuItem;
    View1: TMenuItem;
    Footer2: TMenuItem;
    Header2: TMenuItem;
    InputLine2: TMenuItem;
    Indicator1: TMenuItem;
    N4: TMenuItem;
    HideColumnsWithMouse1: TMenuItem;
    DisableColumnMoving1: TMenuItem;
    Panel1: TPanel;
    btnAdd: TButton;
    Button1: TButton;
    Button3: TButton;
    Button4: TButton;
    Select1: TMenuItem;
    SelectFullRow2: TMenuItem;
    IndicateSelectedCell1: TMenuItem;
    N5: TMenuItem;
    MultiSelect1: TMenuItem;
    Panel2: TPanel;
    Edit1: TMenuItem;
    Search1: TMenuItem;
    ToolButton1: TToolButton;
    btnBold: TToolButton;
    btnItalic: TToolButton;
    btnUnderline: TToolButton;
    ColorPickerEditor1: TNxColorPicker;
    ToolButton2: TToolButton;
    ToolButton11: TToolButton;
    ToolButton23: TToolButton;
    SaveDialog3: TSaveDialog;
    N6: TMenuItem;
    ReportView1: TMenuItem;
    SlideView1: TMenuItem;
    IncrementColumn1: TNxIncrementColumn;
    CheckBoxColumn1: TNxCheckBoxColumn;
    TextualColumn1: TNxTextColumn;
    ImageColumn2: TNxImageColumn;
    ImageColumn1: TNxImageColumn;
    DateColumn1: TNxDateColumn;
    NumericColumn1: TNxNumberColumn;
    ProgressColumn1: TNxProgressColumn;
    ComboBoxColumn1: TNxComboBoxColumn;
    RateColumn1: TNxRateColumn;
    Grid1: TMenuItem;
    Button2: TButton;
    ShowSelectedCount1: TMenuItem;
    procedure Grid1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure btnLeftAlignmentClick(Sender: TObject);
    procedure btnCenterAlignmentClick(Sender: TObject);
    procedure btnRightAlignmentClick(Sender: TObject);
    procedure btnAddRowClick(Sender: TObject);
    procedure btnAddColClick(Sender: TObject);
    procedure ToolButton13Click(Sender: TObject);
    procedure ToolButton14Click(Sender: TObject);
    procedure ToolButton16Click(Sender: TObject);
    procedure ToolButton8Click(Sender: TObject);
    procedure ToolButton17Click(Sender: TObject);
    procedure ToolButton18Click(Sender: TObject);
    procedure ToolButton19Click(Sender: TObject);
    procedure CheckBox7Click(Sender: TObject);
    procedure InsertColumn31Click(Sender: TObject);
    procedure DeleteColumn21Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure CheckBox8Click(Sender: TObject);
    procedure CheckBox9Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure DeleteSelectedRow1Click(Sender: TObject);
    procedure Cells12Test1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure AddRow201Click(Sender: TObject);
    procedure NextGrid1HeaderClick(Sender: TObject; ACol: Integer);
    procedure CheckBox11Click(Sender: TObject);
    procedure NextGrid1SelectCell(Sender: TObject; ACol, ARow: Integer);
    procedure NextGrid1BeforeEdit(Sender: TObject; ACol, ARow: Integer;
      var Accept: Boolean);
    procedure HideFocus1Click(Sender: TObject);
    procedure EditCell261Click(Sender: TObject);
    procedure ToolButton21Click(Sender: TObject);
    procedure ToolButton22Click(Sender: TObject);
    procedure btnAddClick(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure NextGrid1CellColoring(Sender: TObject; ACol, ARow: Integer;
      var CellColor, GridColor: TColor; CellState: TCellState);
    procedure NextGrid1CellClick(Sender: TObject; ACol, ARow: Integer);
    procedure Columns2SortedTrue1Click(Sender: TObject);
    procedure Cell24ColorclRed1Click(Sender: TObject);
    procedure NextGrid1CellFormating(Sender: TObject; ACol, ARow: Integer;
      var TextColor: TColor; var FontStyle: TFontStyles;
      CellState: TCellState);
    procedure urnOnAutoSize1Click(Sender: TObject);
    procedure SaveSettingsToINIFile1Click(Sender: TObject);
    procedure LoadSettingsFromINIFile1Click(Sender: TObject);
    procedure Exit1Click(Sender: TObject);
    procedure Print1Click(Sender: TObject);
    procedure Footer2Click(Sender: TObject);
    procedure Header2Click(Sender: TObject);
    procedure InputLine2Click(Sender: TObject);
    procedure Indicator1Click(Sender: TObject);
    procedure HideColumnsWithMouse1Click(Sender: TObject);
    procedure DisableColumnMoving1Click(Sender: TObject);
    procedure SelectFullRow2Click(Sender: TObject);
    procedure IndicateSelectedCell1Click(Sender: TObject);
    procedure MultiSelect1Click(Sender: TObject);
    procedure NextGrid1FooterClick(Sender: TObject; ACol: Integer);
    procedure Search1Click(Sender: TObject);
    procedure btnBoldClick(Sender: TObject);
    procedure btnItalicClick(Sender: TObject);
    procedure btnUnderlineClick(Sender: TObject);
    procedure ColorPickerEditor1Change(Sender: TObject);
    procedure ToolButton23Click(Sender: TObject);
    procedure NextGrid1EditAccept(Sender: TObject; ACol, ARow: Integer;
      Value: WideString; var Accept: Boolean);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure ReportView1Click(Sender: TObject);
    procedure SlideView1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure ShowSelectedCount1Click(Sender: TObject);
  private
    procedure AddRows(Count: Integer; ShowTimer: Boolean = False);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  Col: Integer;
  pos, pos2: Integer;
  Names: array[0..999] of WideString =
  (
'Smith','Johnson','Williams','Jones','Brown','Davis','Miller','Wilson','Moore', 'Taylor','Anderson',
'Thomas','Jackson','White','Harris','Martin','Thompson','Garcia', 'Martinez','Robinson','Clark',
'Rodriguez','Lewis','Lee','Walker','Hall','Allen','Young','Hernandez','King','Wright','Lopez','Hill',
'Scott','Green','Adams','Baker','Gonzalez','Nelson','Carter','Mitchell','Perez','Roberts','Turner',
'Phillips','Campbell','Parker','Evans','Edwards','Collins','Stewart','Sanchez','Morris','Rogers','Reed',
'Cook','Morgan','Bell','Murphy','Bailey','Rivera','Cooper','Richardson','Cox','Howard','Ward','Torres',
'Peterson','Gray','Ramirez','James','Watson','Brooks','Kelly','Sanders','Price','Bennett','Wood','Barnes',
'Ross','Henderson','Coleman','Jenkins','Perry','Powell','Long','Patterson','Hughes','Flores','Washington','Butler',
'Simmons','Foster','Gonzales','Bryant','Alexander','Russell','Griffin','Diaz','Hayes','Myers','Ford','Hamilton',
'Graham','Sullivan','Wallace','Woods','Cole','West','Jordan','Owens','Reynolds','Fisher','Ellis','Harrison','Gibson',
'McDonald','Cruz','Marshall','Ortiz','Gomez','Murray','Freeman','Wells','Webb','Simpson','Stevens','Tucker','Porter','Hunter',
'Hicks','Crawford','Henry','Boyd','Mason','Morales','Kennedy','Warren','Dixon','Ramos','Reyes','Burns','Gordon','Shaw','Holmes',
'Rice','Robertson','Hunt','Black','Daniels','Palmer','Mills','Nichols','Grant','Knight','Ferguson','Rose','Stone','Hawkins',
'Dunn','Perkins','Hudson','Spencer','Gardner','Stephens','Payne','Pierce','Berry','Matthews','Arnold','Wagner','Willis',
'Ray','Watkins','Olson','Carroll','Duncan','Snyder','Hart','Cunningham','Bradley','Lane','Andrews','Ruiz','Harper','Fox',
'Riley','Armstrong','Carpenter','Weaver','Greene','Lawrence','Elliott','Chavez','Sims','Austin','Peters','Kelley','Franklin',
'Lawson','Fields','Gutierrez','Ryan','Schmidt','Carr','Vasquez','Castillo','Wheeler','Chapman','Oliver','Montgomery',
'Richards','Williamson','Johnston','Banks','Meyer','Bishop','McCoy','Howell','Alvarez','Morrison','Hansen','Fernandez',
'Garza','Harvey','Little','Burton','Stanley','Nguyen','George','Jacobs','Reid','Kim','Fuller','Lynch','Dean','Gilbert',
'Garrett','Romero','Welch','Larson','Frazier','Burke','Hanson','Day','Mendoza','Moreno','Bowman','Medina','Fowler',
'Brewer','Hoffman','Carlson','Silva','Pearson','Holland','Douglas','Fleming','Jensen','Vargas','Byrd','Davidson',
'Hopkins','May','Terry','Herrera','Wade','Soto','Walters','Curtis','Neal','Caldwell','Lowe','Jennings','Barnett',
'Graves','Jimenez','Horton','Shelton','Barrett','OBrien','Castro','Sutton','Gregory','McKinney','Lucas','Miles',
'Craig','Rodriquez','Chambers','Holt','Lambert','Fletcher','Watts','Bates','Hale','Rhodes','Pena','Beck','Newman',
'Haynes','McDaniel','Mendez','Bush','Vaughn','Parks','Dawson','Santiago','Norris','Hardy','Love','Steele','Curry',
'Powers','Schultz','Barker','Guzman','Page','Munoz','Ball','Keller','Chandler','Weber','Leonard','Walsh','Lyons',
'Ramsey','Wolfe','Schneider','Mullins','Benson','Sharp','Bowen','Daniel','Barber','Cummings','Hines','Baldwin',
'Griffith','Valdez','Hubbard','Salazar','Reeves','Warner','Stevenson','Burgess','Santos','Tate','Cross','Garner',
'Mann','Mack','Moss','Thornton','Dennis','McGee','Farmer','Delgado','Aguilar','Vega','Glover','Manning','Cohen',
'Harmon','Rodgers','Robbins','Newton','Todd','Blair','Higgins','Ingram','Reese','Cannon','Strickland','Townsend',
'Potter','Goodwin','Walton','Rowe','Hampton','Ortega','Patton','Swanson','Joseph','Francis','Goodman','Maldonado',
'Yates','Becker','Erickson','Hodges','Rios','Conner','Adkins','Webster','Norman','Malone','Hammond','Flowers',
'Cobb','Moody','Quinn','Blake','Maxwell','Pope','Floyd','Osborne','Paul','McCarthy','Guerrero','Lindsey','Estrada',
'Sandoval','Gibbs','Tyler','Gross','Fitzgerald','Stokes','Doyle','Sherman','Saunders','Wise','Colon','Gill',
'Alvarado','Greer','Padilla','Simon','Waters','Nunez','Ballard','Schwartz','McBride','Houston','Christensen',
'Klein','Pratt','Briggs','Parsons','McLaughlin','Zimmerman','French','Buchanan','Moran','Copeland','Roy','Pittman',
'Brady','McCormick','Holloway','Brock','Poole','Frank','Logan','Owen','Bass','Marsh','Drake','Wong','Jefferson',
'Park','Morton','Abbott','Sparks','Patrick','Norton','Huff','Clayton','Massey','Lloyd','Figueroa','Carson',
'Bowers','Roberson','Barton','Tran','Lamb','Harrington','Casey','Boone','Cortez','Clarke','Mathis','Singleton',
'Wilkins','Cain','Bryan','Underwood','Hogan','McKenzie','Collier','Luna','Phelps','McGuire','Allison','Bridges',
'Wilkerson','Nash','Summers','Atkins','Wilcox','Pitts','Conley','Marquez','Burnett','Richard','Cochran','Chase',
'Davenport','Hood','Gates','Clay','Ayala','Sawyer','Roman','Vazquez','Dickerson','Hodge','Acosta','Flynn',
'Espinoza','Nicholson','Monroe','Wolf','Morrow','Kirk','Randall','Anthony','Whitaker','OConnor','Skinner','Ware',
'Molina','Kirby','Huffman','Bradford','Charles','Gilmore','Dominguez','ONeal','Bruce','Lang','Combs','Kramer',
'Heath','Hancock','Gallagher','Gaines','Shaffer','Short','Wiggins','Mathews','McClain','Fischer','Wall','Small',
'Melton','Hensley','Bond','Dyer','Cameron','Grimes','Contreras','Christian','Wyatt','Baxter','Snow','Mosley',
'Shepherd','Larsen','Hoover','Beasley','Glenn','Petersen','Whitehead','Meyers','Keith','Garrison','Vincent',
'Shields','Horn','Savage','Olsen','Schroeder','Hartman','Woodard','Mueller','Kemp','Deleon','Booth','Patel',
'Calhoun','Wiley','Eaton','Cline','Navarro','Harrell','Lester','Humphrey','Parrish','Duran','Hutchinson','Hess',
'Dorsey','Bullock','Robles','Beard','Dalton','Avila','Vance','Rich','Blackwell','York','Johns','Blankenship',
'Trevino','Salinas','Campos','Pruitt','Moses','Callahan','Golden','Montoya','Hardin','Guerra','McDowell','Carey',
'Stafford','Gallegos','Henson','Wilkinson','Booker','Merritt','Miranda','Atkinson','Orr','Decker','Hobbs','Preston',
'Tanner','Knox','Pacheco','Stephenson','Glass','Rojas','Serrano','Marks','Hickman','English','Sweeney','Strong',
'Prince','McClure','Conway','Walter','Roth','Maynard','Farrell','Lowery','Hurst','Nixon','Weiss','Trujillo',
'Ellison','Sloan','Juarez','Winters','McLean','Randolph','Leon','Boyer','Villarreal','McCall','Gentry','Carrillo',
'Kent','Ayers','Lara','Shannon','Sexton','Pace','Hull','Leblanc','Browning','Velasquez','Leach','Chang','House',
'Sellers','Herring','Noble','Foley','Bartlett','Mercado','Landry','Durham','Walls','Barr','McKee','Bauer','Rivers',
'Everett','Bradshaw','Pugh','Velez','Rush','Estes','Dodson','Morse','Sheppard','Weeks','Camacho','Bean','Barron',
'Livingston','Middleton','Spears','Branch','Blevins','Chen','Kerr','McConnell','Hatfield','Harding','Ashley',
'Solis','Herman','Frost','Giles','Blackburn','William','Pennington','Woodward','Finley','McIntosh','Koch','Best',
'Solomon','McCullough','Dudley','Nolan','Blanchard','Rivas','Brennan','Mejia','Kane','Benton','Joyce','Buckley',
'Haley','Valentine','Maddox','Russo','McKnight','Buck','Moon','McMillan','Crosby','Berg','Dotson','Mays','Roach',
'Church','Chan','Richmond','Meadows','Faulkner','ONeill','Knapp','Kline','Barry','Ochoa','Jacobson','Gay','Avery',
'Hendricks','Horne','Shepard','Hebert','Cherry','Cardenas','McIntyre','Whitney','Waller','Holman','Donaldson',
'Cantu','Terrell','Morin','Gillespie','Fuentes','Tillman','Sanford','Bentley','Peck','Key','Salas','Rollins',
'Gamble','Dickson','Battle','Santana','Cabrera','Cervantes','Howe','Hinton','Hurley','Spence','Zamora','Yang',
'McNeil','Suarez','Case','Petty','Gould','McFarland','Sampson','Carver','Bray','Rosario','MacDonald','Stout',
'Hester','Melendez','Dillon','Farley','Hopper','Galloway','Potts','Bernard','Joyner','Stein','Aguirre','Osborn',
'Mercer','Bender','Franco','Rowland','Sykes','Benjamin','Travis','Pickett','Crane','Sears','Mayo','Dunlap','Hayden',
'Wilder','McKay','Coffey','McCarty','Ewing','Cooley','Vaughan','Bonner','Cotton','Holder','Stark','Ferrell','Cantrell',
'Fulton','Lynn','Lott','Calderon','Rosa','Pollard','Hooper','Burch','Mullen','Fry','Riddle','Levy','David','Duke',
'ODonnell','Guy','Michael','Britt','Frederick','Daugherty','Berger','Dillard','Alston','Jarvis','Frye','Riggs',
'Chaney','Odom','Duffy','Fitzpatrick','Valenzuela','Merrill','Mayer','Alford','McPherson','Acevedo','Donovan',
'Barrera','Albert','Cote','Reilly','Compton','Raymond','Mooney','McGowan','Craft','Cleveland','Clemons','Wynn',
'Nielsen','Baird','Stanton','Snider','Rosales','Bright','Witt','Stuart','Hays','Holden','Rutledge','Kinney',
'Clements','Castaneda','Slater','Hahn','Emerson','Conrad','Burks','Delaney','Pate','Lancaster','Sweet','Justice',
'Tyson','Sharpe','Whitfield','Talley','Macias','Irwin','Burris','Ratliff','McCray','Madden','Kaufman','Beach','Goff',
'Cash','Bolton','McFadden','Levine','Good','Byers','Kirkland','Kidd','Workman','Carney','Dale','McLeod','Holcomb',
'England','Finch','Head','Burt','Hendrix','Sosa','Haney','Franks','Sargent','Nieves','Downs','Rasmussen','Bird','Hewitt',
'Lindsay','Le','Foreman','Valencia','ONeil','Delacruz','Vinson','Dejesus','Hyde','Forbes','Gilliam','Guthrie','Wooten',
'Huber','Barlow','Boyle','McMahon','Buckner','Rocha','Puckett','Langley','Knowles','Cooke','Velazquez','Whitley','Noel','Vang');

  Checks: array[0..2] of string = ('yes', 'no', 'unknown');
  Cards: array[0..3] of WideString = ('Visa', 'MasterCard', 'Express', 'Other');

implementation

uses
  Unit2, Math, Unit3;

{$R *.dfm}

procedure TForm1.AddRows(Count: Integer; ShowTimer: Boolean = False);
var
  i, n: Integer;
  t1, t2: TDateTime;
begin
//  NextGrid1.Options := NextGrid1.Options - [goUseDefaultValues];
  n := Count;
  t1 := now;
  NextGrid1.AddRow(n);
  NextGrid1.BeginUpdate; { much faster, skip OnChange and Cell refreshing }
  for i := NextGrid1.RowCount - n to NextGrid1.RowCount - 1 do
  begin
    NextGrid1.Cell[1, i].AsBoolean := False;
    NextGrid1.Cell[2, i].AsString := Names[Random(1000)] + ' ' + Names[Random(1000)];
    NextGrid1.Cell[3, i].AsInteger := Random(2);
    NextGrid1.Cell[4, i].AsDateTime := Today+Random(500);
    NextGrid1.Cell[5, i].AsFloat := Random(2000);
    NextGrid1.Cell[6, i].AsInteger := Random(101);
    NextGrid1.Cell[7, i].AsString := Cards[Random(4)];
    NextGrid1.Cell[8, i].AsInteger := Random(6);
    NextGrid1.Cell[9, i].AsInteger := Random(2) - 1;
    if NextGrid1.Cell[9, i].AsInteger = 0 then NextGrid1.Cell[9, i].Hint := 'Delete Row';
  end;
  NextGrid1.EndUpdate;
  t2 := now;
  if ShowTimer then ShowMessage('Duration :' + IntToStr(MilliSecondsBetween(t1, t2)) + ' Milliseconds');
//  NextGrid1.Options := NextGrid1.Options + [goUseDefaultValues];
end;

procedure TForm1.Grid1Click(Sender: TObject);
begin
  if TMenuItem(Sender).Checked
    then NextGrid1.Options := NextGrid1.Options + [goGrid]
      else NextGrid1.Options := NextGrid1.Options - [goGrid];
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  C: HCURSOR;
begin
  C := LoadCursor(0, IDC_HAND);
  if C <> 0 then Screen.Cursors[crHandPoint] := C;
  ToolBar2.ControlStyle := ToolBar2.ControlStyle - [csCaptureMouse];
end;

procedure TForm1.btnLeftAlignmentClick(Sender: TObject);
begin
  NextGrid1.Columns[NextGrid1.SelectedColumn].Alignment := taLeftJustify;
end;

procedure TForm1.btnCenterAlignmentClick(Sender: TObject);
begin
  NextGrid1.Columns[NextGrid1.SelectedColumn].Alignment := taCenter;
end;

procedure TForm1.btnRightAlignmentClick(Sender: TObject);
begin
  NextGrid1.Columns[NextGrid1.SelectedColumn].Alignment := taRightJustify;
end;

procedure TForm1.btnAddRowClick(Sender: TObject);
begin
  NextGrid1.AddRow;
  NextGrid1.SelectLastRow;
end;

procedure TForm1.btnAddColClick(Sender: TObject);
begin
  if form2.ShowModal = mrOk then
  begin
    if Form2.ComboBox1.Text = 'TNxCheckBoxColumn' then NextGrid1.Columns.Add(TNxCheckBoxColumn, '');
    if Form2.ComboBox1.Text = 'TNxImageColumn' then NextGrid1.Columns.Add(TNxImageColumn, '');
    if Form2.ComboBox1.Text = 'TNxIncrementColumn' then NextGrid1.Columns.Add(TNxIncrementColumn, '');
    if Form2.ComboBox1.Text = 'TNxRateColumn' then NextGrid1.Columns.Add(TNxRateColumn, '');
    if Form2.ComboBox1.Text = 'TNxComboBoxColumn' then NextGrid1.Columns.Add(TNxComboBoxColumn, '');
    if Form2.ComboBox1.Text = 'TNxProgressColumn' then NextGrid1.Columns.Add(TNxProgressColumn, '');
    if Form2.ComboBox1.Text = 'TNxNumberColumn' then NextGrid1.Columns.Add(TNxNumberColumn, '');
    if Form2.ComboBox1.Text = 'TNxTextColumn' then NextGrid1.Columns.Add(TNxTextColumn, '');

    if Form2.ComboBox2.Text = 'fkAverage' then NextGrid1.Columns[NextGrid1.Columns.Count-1].Footer.FormulaKind := fkAverage;
    if Form2.ComboBox2.Text = 'fkMaximum' then NextGrid1.Columns[NextGrid1.Columns.Count-1].Footer.FormulaKind := fkMaximum;
    if Form2.ComboBox2.Text = 'fkMinimum' then NextGrid1.Columns[NextGrid1.Columns.Count-1].Footer.FormulaKind := fkMinimum;
    if Form2.ComboBox2.Text = 'fkSum' then NextGrid1.Columns[NextGrid1.Columns.Count-1].Footer.FormulaKind := fkSum;
  end;
end;

procedure TForm1.ToolButton13Click(Sender: TObject);
begin
  NextGrid1.ClearRows;
end;

procedure TForm1.ToolButton14Click(Sender: TObject);
begin
  NextGrid1.DeleteRow(NextGrid1.SelectedRow);
end;

procedure TForm1.ToolButton16Click(Sender: TObject);
begin
  NextGrid1.Columns.Delete(NextGrid1.SelectedColumn);
end;

procedure TForm1.ToolButton8Click(Sender: TObject);
begin
  NextGrid1.MoveRow(NextGrid1.SelectedRow, NextGrid1.SelectedRow - 1);
  NextGrid1.SelectedRow := NextGrid1.SelectedRow - 1;
end;

procedure TForm1.ToolButton17Click(Sender: TObject);
begin
  NextGrid1.MoveRow(NextGrid1.SelectedRow, NextGrid1.SelectedRow + 1);
  NextGrid1.SelectedRow := NextGrid1.SelectedRow + 1;
end;

procedure TForm1.ToolButton18Click(Sender: TObject);
var
  o, n: Integer;
begin
  o := NextGrid1.Columns[NextGrid1.SelectedColumn].Position;
  if o = 0 then Exit;
  n := o - 1;
  NextGrid1.Columns.ChangePosition(o, n);
end;

procedure TForm1.ToolButton19Click(Sender: TObject);
var
  o, n: Integer;
begin
  o := NextGrid1.Columns[NextGrid1.SelectedColumn].Position;
  n := o + 1;
  NextGrid1.Columns.ChangePosition(o, n);
end;

procedure TForm1.CheckBox7Click(Sender: TObject);
begin
  NextGrid1.Columns[5].Visible := TCheckBox(Sender).Checked;
end;

procedure TForm1.InsertColumn31Click(Sender: TObject);
begin
  NextGrid1.Columns.Insert(TNxTextColumn, 3);
  btnAdd.Enabled := False;
end;

procedure TForm1.DeleteColumn21Click(Sender: TObject);
begin
  NextGrid1.Columns.Delete(2);
  btnAdd.Enabled := False;
end;

procedure TForm1.ToolButton3Click(Sender: TObject);
begin
  NextGrid1.Columns[NextGrid1.SelectedColumn].VerticalAlignment := taAlignTop;
end;

procedure TForm1.ToolButton4Click(Sender: TObject);
begin
  NextGrid1.Columns[NextGrid1.SelectedColumn].VerticalAlignment := taVerticalCenter;
end;

procedure TForm1.ToolButton5Click(Sender: TObject);
begin
  NextGrid1.Columns[NextGrid1.SelectedColumn].VerticalAlignment := taAlignBottom;
end;

procedure TForm1.CheckBox8Click(Sender: TObject);
begin
  NextGrid1.Columns[6].Visible := TCheckBox(Sender).Checked;
end;

procedure TForm1.CheckBox9Click(Sender: TObject);
begin
  NextGrid1.Columns[7].Visible := TCheckBox(Sender).Checked;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  AddRows(10);
end;

procedure TForm1.DeleteSelectedRow1Click(Sender: TObject);
begin
  NextGrid1.DeleteRow(NextGrid1.SelectedRow);
end;

procedure TForm1.Cells12Test1Click(Sender: TObject);
begin
	if NextGrid1.RowCount > 2 then NextGrid1.Cells[2, 2] := 'Test';
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  AddRows(10000);
end;

procedure TForm1.AddRow201Click(Sender: TObject);
begin
  NextGrid1.AddRow(10);
end;

procedure TForm1.NextGrid1HeaderClick(Sender: TObject; ACol: Integer);
begin
	if ACol = 0 then ShowMessage('This column can not be sorted (OnHeaderClick Event).');
end;

procedure TForm1.CheckBox11Click(Sender: TObject);
begin
  NextGrid1.Columns[8].Visible := TCheckBox(Sender).Checked;
end;

procedure TForm1.NextGrid1SelectCell(Sender: TObject; ACol, ARow: Integer);
begin
  if NextGrid1.Columns[NextGrid1.SelectedColumn].Alignment = taLeftJustify then btnLeftAlignment.Down := True;
  if NextGrid1.Columns[NextGrid1.SelectedColumn].Alignment = taCenter then btnCenterAlignment.Down := True;
  if NextGrid1.Columns[NextGrid1.SelectedColumn].Alignment = taRightJustify then btnRightAlignment.Down := True;
  btnBold.Down := fsBold in NextGrid1.Cell[ACol, ARow].FontStyle;
  btnItalic.Down := fsItalic in NextGrid1.Cell[ACol, ARow].FontStyle;
  btnUnderline.Down := fsUnderline in NextGrid1.Cell[ACol, ARow].FontStyle;
  ColorPickerEditor1.SelectedColor := NextGrid1.Cell[ACol, ARow].Color;
end;

procedure TForm1.NextGrid1BeforeEdit(Sender: TObject; ACol, ARow: Integer;
  var Accept: Boolean);
begin
	if ((ACol = 2) and (ARow = 2)) or ((ACol = 1) and (ARow = 3)) then
  begin
    ShowMessage('OnBeforeEditEvent: Editing this cell is disabled.');
    Accept := False;
  end;
end;

procedure TForm1.HideFocus1Click(Sender: TObject);
begin
  if TMenuItem(Sender).Checked
    then NextGrid1.AppearanceOptions := NextGrid1.AppearanceOptions + [aoHideFocus]
      else NextGrid1.AppearanceOptions := NextGrid1.AppearanceOptions - [aoHideFocus];
end;

procedure TForm1.EditCell261Click(Sender: TObject);
begin
  NextGrid1.EditCell(2, 6);
end;

procedure TForm1.ToolButton21Click(Sender: TObject);
begin
	if SaveDialog2.Execute then NextGrid1.SaveToTextFile(SaveDialog2.FileName);
end;

procedure TForm1.ToolButton22Click(Sender: TObject);
begin
	if OpenDialog1.Execute then NextGrid1.LoadFromTextFile(OpenDialog1.FileName);
  Application.ProcessMessages;
end;

procedure TForm1.btnAddClick(Sender: TObject);
begin
  AddRows(100000, True);
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
  AddRows(30000, True);
end;

procedure TForm1.NextGrid1CellColoring(Sender: TObject; ACol,
  ARow: Integer; var CellColor, GridColor: TColor; CellState: TCellState);
begin
	if (ACol = 2) and (ARow = 2) then
	begin
	  NextGrid1.Canvas.Font.Color := clRed;
	  NextGrid1.Canvas.Font.Style := [fsBold];
	end;
end;

procedure TForm1.NextGrid1CellClick(Sender: TObject; ACol, ARow: Integer);
begin
  if ACol = 9 then
  begin
    if NextGrid1.Cells[9, ARow] = '0' then NextGrid1.DeleteRow(ARow);
  end;
end;

procedure TForm1.Columns2SortedTrue1Click(Sender: TObject);
begin
  NextGrid1.Columns[6].SortKind := skDescending;
  NextGrid1.Columns[6].Sorted := True;
end;

procedure TForm1.Cell24ColorclRed1Click(Sender: TObject);
begin
  NextGrid1.Cell[2, 4].Color := clRed;
end;

procedure TForm1.NextGrid1CellFormating(Sender: TObject; ACol,
  ARow: Integer; var TextColor: TColor; var FontStyle: TFontStyles;
  CellState: TCellState);
begin
  if (ACol = 5) then
  begin
    if (NextGrid1.Cell[5, ARow].AsInteger < 200) then TextColor := clRed;
    if (NextGrid1.Cell[5, ARow].AsInteger > 1800) then TextColor := clBlue;
  end;
end;

procedure TForm1.urnOnAutoSize1Click(Sender: TObject);
var
	i: Integer;
begin
	for i := 0 to NextGrid1.Columns.Count - 1 do
  begin
    if TMenuItem(Sender).Checked
      then NextGrid1.Columns[i].Options := NextGrid1.Columns[i].Options + [coAutoSize]
        else NextGrid1.Columns[i].Options := NextGrid1.Columns[i].Options - [coAutoSize];
  end;
end;

procedure TForm1.SaveSettingsToINIFile1Click(Sender: TObject);
begin
  NextGrid1.SaveToIni(ExtractFilePath(ParamStr(0))+ 'IniFile.ini');
end;

procedure TForm1.LoadSettingsFromINIFile1Click(Sender: TObject);
begin
  NextGrid1.LoadFromIni(ExtractFilePath(ParamStr(0))+ 'IniFile.ini');
end;

procedure TForm1.Exit1Click(Sender: TObject);
begin
  Close;
end;

procedure TForm1.Print1Click(Sender: TObject);
begin
	if PrintDialog1.Execute then GridPrint1.Print;
end;

procedure TForm1.Footer2Click(Sender: TObject);
begin
  if TMenuItem(Sender).Checked
    then NextGrid1.Options := NextGrid1.Options + [goFooter]
      else NextGrid1.Options := NextGrid1.Options - [goFooter];
end;

procedure TForm1.Header2Click(Sender: TObject);
begin
  if TMenuItem(Sender).Checked
    then NextGrid1.Options := NextGrid1.Options + [goHeader]
      else NextGrid1.Options := NextGrid1.Options - [goHeader];
end;

procedure TForm1.InputLine2Click(Sender: TObject);
begin
  if TMenuItem(Sender).Checked
    then NextGrid1.Options := NextGrid1.Options + [goInput]
      else NextGrid1.Options := NextGrid1.Options - [goInput];
end;

procedure TForm1.Indicator1Click(Sender: TObject);
begin
  if TMenuItem(Sender).Checked
    then NextGrid1.Options := NextGrid1.Options + [goIndicator]
      else NextGrid1.Options := NextGrid1.Options - [goIndicator];

end;

procedure TForm1.HideColumnsWithMouse1Click(Sender: TObject);
begin
  if TMenuItem(Sender).Checked
    then NextGrid1.Options := NextGrid1.Options + [goCanHideColumn]
      else NextGrid1.Options := NextGrid1.Options - [goCanHideColumn];

end;

procedure TForm1.DisableColumnMoving1Click(Sender: TObject);
begin
  if TMenuItem(Sender).Checked
    then NextGrid1.Options := NextGrid1.Options + [goDisableColumnMoving]
      else NextGrid1.Options := NextGrid1.Options - [goDisableColumnMoving];
end;

procedure TForm1.SelectFullRow2Click(Sender: TObject);
begin
  if TMenuItem(Sender).Checked
    then NextGrid1.Options := NextGrid1.Options + [goSelectFullRow]
      else NextGrid1.Options := NextGrid1.Options - [goSelectFullRow];
end;

procedure TForm1.IndicateSelectedCell1Click(Sender: TObject);
begin
  if TMenuItem(Sender).Checked
    then NextGrid1.AppearanceOptions := NextGrid1.AppearanceOptions + [aoIndicateSelectedCell]
      else NextGrid1.AppearanceOptions := NextGrid1.AppearanceOptions - [aoIndicateSelectedCell];

end;

procedure TForm1.MultiSelect1Click(Sender: TObject);
begin
  if TMenuItem(Sender).Checked
    then NextGrid1.Options := NextGrid1.Options + [goMultiSelect]
      else NextGrid1.Options := NextGrid1.Options - [goMultiSelect];

end;

procedure TForm1.NextGrid1FooterClick(Sender: TObject; ACol: Integer);
begin
  if ACol = 5 then NextGrid1.CalculateFooter;
end;

procedure TForm1.Search1Click(Sender: TObject);
begin
  Form3.Show;
end;

procedure TForm1.btnBoldClick(Sender: TObject);
begin
  with NextGrid1 do
    if CellBounds(SelectedColumn, SelectedRow) then
      if TToolButton(Sender).Down
        then Cell[SelectedColumn, SelectedRow].FontStyle := Cell[SelectedColumn, SelectedRow].FontStyle + [fsBold]
        else Cell[SelectedColumn, SelectedRow].FontStyle := Cell[SelectedColumn, SelectedRow].FontStyle - [fsBold];
end;

procedure TForm1.btnItalicClick(Sender: TObject);
begin
  with NextGrid1 do
    if CellBounds(SelectedColumn, SelectedRow) then
      if TToolButton(Sender).Down
        then Cell[SelectedColumn, SelectedRow].FontStyle := Cell[SelectedColumn, SelectedRow].FontStyle + [fsItalic]
        else Cell[SelectedColumn, SelectedRow].FontStyle := Cell[SelectedColumn, SelectedRow].FontStyle - [fsItalic];
end;

procedure TForm1.btnUnderlineClick(Sender: TObject);
begin
  with NextGrid1 do
    if CellBounds(SelectedColumn, SelectedRow) then
      if TToolButton(Sender).Down
        then Cell[SelectedColumn, SelectedRow].FontStyle := Cell[SelectedColumn, SelectedRow].FontStyle + [fsUnderline]
        else Cell[SelectedColumn, SelectedRow].FontStyle := Cell[SelectedColumn, SelectedRow].FontStyle - [fsUnderline];
end;

procedure TForm1.ColorPickerEditor1Change(Sender: TObject);
begin
  with NextGrid1 do
    if CellBounds(SelectedColumn, SelectedRow) then
    begin
      if ColorPickerEditor1.SelectedColor = clNone
        then Cell[SelectedColumn, SelectedRow].Color := Color
        else Cell[SelectedColumn, SelectedRow].Color := ColorPickerEditor1.SelectedColor;
    end;
end;

procedure TForm1.ToolButton23Click(Sender: TObject);
begin
  if SaveDialog3.Execute then
  begin
    NextGrid1.SaveToHTML(SaveDialog3.FileName);
  end;
end;

procedure TForm1.NextGrid1EditAccept(Sender: TObject; ACol, ARow: Integer;
  Value: WideString; var Accept: Boolean);
begin
  if Value = '-1' then
  begin
    Accept := False;
    ShowMessage('This Value is not accapted');
  end;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  NextGrid1.ApplyEditing;
end;

procedure TForm1.ReportView1Click(Sender: TObject);
begin
  NextGrid1.GridStyle := gsReport;
end;

procedure TForm1.SlideView1Click(Sender: TObject);
begin
  NextGrid1.GridStyle := gsSlides;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  AddRows(5);
end;

procedure TForm1.ShowSelectedCount1Click(Sender: TObject);
begin
  ShowMessage(IntToStr(NextGrid1.SelectedCount));
end;

end.
