//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "DemoNextGridPrj.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "NxColumnClasses"
#pragma link "NxColumns"
#pragma link "NxCustomGrid"
#pragma link "NxCustomGridControl"
#pragma link "NxEdit"
#pragma link "NxGrid"
#pragma link "NxGridPrint"
#pragma link "NxScrollControl"
#pragma resource "*.dfm"
TForm1 *Form1;
int Col;
int pos, pos2;
WideString Names[1000] =  {
        "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",
        "Wilkerson","Nash", "Summers", "Atkins","Wilcox","Pitts","Conley","Marquez","Burnett","Richard","Cochran","Chase"
        "Wilkins","Cain","Bryan","Underwood","Hogan","McKenzie","Collier","Luna","Phelps","McGuire","Allison","Bridges",
        "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"
};
/*
*/
AnsiString  Checks[3] = {  "yes" ,  "no", "unknown" };
WideString  Cards[4]  = { "Visa", "MasterCard", "Express", "Other" };


//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
        HCURSOR   C = LoadCursor(0, IDC_HAND);
        if (C)
                Screen->Cursors[crHandPoint] = C;
        ToolBar2->ControlStyle = ToolBar2->ControlStyle >> csCaptureMouse;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::AddRows(int Count, bool ShowTimer)
{
int  i, n;
TDateTime  t1, t2;

//  NextGrid1.Options = NextGrid1.Options - [goUseDefaultValues];
        n = Count;
        t1 = Now();
        NextGrid1->AddRow(n);
        NextGrid1->Update();  //{ much faster, skip OnChange and Cell refreshing }
        for (i = NextGrid1->RowCount - n; i < NextGrid1->RowCount; ++i) {
                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)
                        NextGrid1->Cell[9][i]->Hint = "Delete Row";
        }
        NextGrid1->EndUpdate();
        t2 = Now();
        if (ShowTimer)
                ShowMessage("Duration :" + IntToStr(MilliSecondsBetween(t1, t2)) + " Milliseconds");
//  NextGrid1->Options = NextGrid1->Options + [goUseDefaultValues];
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Grid1Click(TObject  *Sender)
{
        TMenuItem *Itm = dynamic_cast<TMenuItem *> (Sender);
        if (Itm->Checked)
                NextGrid1->Options = NextGrid1->Options  << goGrid;
        else NextGrid1->Options = NextGrid1->Options >> goGrid;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btnLeftAlignmentClick(TObject  *Sender)
{
        NextGrid1->Columns->Item[NextGrid1->SelectedColumn]->Alignment = taLeftJustify;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btnCenterAlignmentClick(TObject  *Sender)
{
        NextGrid1->Columns->Item[NextGrid1->SelectedColumn]->Alignment = taCenter;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btnRightAlignmentClick(TObject  *Sender)
{
         NextGrid1->Columns->Item[NextGrid1->SelectedColumn]->Alignment = taRightJustify;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btnAddRowClick(TObject  *Sender)
{
        NextGrid1->AddRow();
        NextGrid1->SelectLastRow();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btnAddColClick(TObject  *Sender)
{
/*        if (Form2->ShowModal() = mrOk ) {
                if (Form2->ComboBox1->Text == "TNxCheckBoxColumn")
                        NextGrid1->Columns->Add(TNxCheckBoxColumn);
                if (Form2->ComboBox1->Text == "TNxImageColumn"
                        NextGrid1->Columns->Add(TNxImageColumn);
                if (Form2->ComboBox1->Text == "TNxIncrementColumn"
                        NextGrid1->Columns->Add(TNxIncrementColumn);
                if (Form2->ComboBox1->Text == "TNxRateColumn"
                        NextGrid1->Columns->Add(TNxRateColumn);
                if (Form2->ComboBox1->Text == "TNxComboBoxColumn"
                        NextGrid1->Columns->Add(TNxComboBoxColumn);
                if Form2->ComboBox1->Text == "TNxProgressColumn"'
                        NextGrid1->Columns->Add(TNxProgressColumn);
                if (Form2->ComboBox1->Text == "TNxNumberColumn"
                        NextGrid1->Columns->Add(TNxNumberColumn);
                if (Form2->ComboBox1->Text == "TNxTextColumn")
                        NextGrid1->Columns.Add(TNxTextColumn);
                if (Form2->ComboBox2->Text == "fkAverage")
                        NextGrid1->Columns[NextGrid1->Columns->Count-1]->Footer->FormulaKind = fkAverage;
                if (Form2->ComboBox2->Text == "fkMaximum")
                        NextGrid1->Columns[NextGrid1->Columns->Count-1]->Footer->FormulaKind = fkMaximum;
                if (Form2->ComboBox2->Text == "fkMinimum")
                        NextGrid1->Columns[NextGrid1->Columns->Count-1]->Footer->FormulaKind = fkMinimum;
                if (Form2->ComboBox2->Text == "fkSum")
                        NextGrid1->Columns[NextGrid1->Columns->Count-1]->Footer->FormulaKind = fkSum;
        }       */
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ToolButton13Click(TObject  *Sender)
{
        NextGrid1->ClearRows();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ToolButton14Click(TObject  *Sender)
{
        NextGrid1->DeleteRow(NextGrid1->SelectedRow);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ToolButton16Click(TObject  *Sender)
{
        NextGrid1->Columns->Delete(NextGrid1->SelectedColumn);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ToolButton8Click(TObject  *Sender)
{
        NextGrid1->MoveRow(NextGrid1->SelectedRow, NextGrid1->SelectedRow - 1);
        NextGrid1->SelectedRow = NextGrid1->SelectedRow - 1;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ToolButton17Click(TObject  *Sender)
{
        NextGrid1->MoveRow(NextGrid1->SelectedRow, NextGrid1->SelectedRow + 1);
        NextGrid1->SelectedRow = NextGrid1->SelectedRow + 1;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ToolButton18Click(TObject  *Sender)
{
int o, n;

        o = NextGrid1->Columns->Item[NextGrid1->SelectedColumn]->Position;
        if (o == 0) return;
        n = o - 1;
        NextGrid1->Columns->ChangePosition(o, n);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ToolButton19Click(TObject  *Sender)
{
int o, n;

//        o = NextGrid1->Columns[NextGrid1->SelectedColumn]->Position;
        n = o + 1;
        NextGrid1->Columns->ChangePosition(o, n);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::CheckBox7Click(TObject  *Sender)
{
        TCheckBox * ChckBx = dynamic_cast<TCheckBox *> (Sender);
        NextGrid1->Columns->Item[5]->Visible = ChckBx->Checked;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::InsertColumn31Click(TObject  *Sender)
{
//        NextGrid1->Columns->Insert(TNxTextColumn, 3);
        btnAdd->Enabled = false;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::DeleteColumn21Click(TObject  *Sender)
{
        NextGrid1->Columns->Delete(2);
        btnAdd->Enabled = false;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ToolButton3Click(TObject  *Sender)
{
//        NextGrid1->Columns[NextGrid1->SelectedColumn]->VerticalAlignment = taAlignTop;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ToolButton4Click(TObject  *Sender)
{
//        NextGrid1->Columns[NextGrid1->SelectedColumn]->VerticalAlignment = taVerticalCenter;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ToolButton5Click(TObject  *Sender)
{
//        NextGrid1->Columns[NextGrid1->SelectedColumn]->VerticalAlignment = taAlignBottom;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::CheckBox8Click(TObject  *Sender)
{
        TCheckBox * ChckBx = dynamic_cast<TCheckBox *> (Sender);
//        NextGrid1-> Columns[6]->Visible = ChckBx->Checked;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::CheckBox9Click(TObject  *Sender)
{
        TCheckBox * ChckBx = dynamic_cast<TCheckBox *> (Sender);
        NextGrid1->Columns->Item[7]->Visible = ChckBx->Checked;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject  *Sender)
{
        AddRows(10);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::DeleteSelectedRow1Click(TObject  *Sender)
{
        NextGrid1->DeleteRow(NextGrid1->SelectedRow);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Cells12Test1Click(TObject  *Sender)
{
	if (NextGrid1->RowCount > 2)
                NextGrid1->Cells[2][2] = "Test";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject  *Sender)
{
        AddRows(10000);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::AddRow201Click(TObject  *Sender)
{
        NextGrid1->AddRow(10);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::CheckBox11Click(TObject  *Sender)
{
        TCheckBox * ChckBx = dynamic_cast<TCheckBox *> (Sender);
        NextGrid1->Columns->Item[8]->Visible = ChckBx->Checked;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NextGrid1SelectCell(TObject *Sender, int ACol, int ARow)
{
        if (NextGrid1->Columns->Item[NextGrid1->SelectedColumn]->Alignment == taLeftJustify ||
                NextGrid1->Columns->Item[NextGrid1->SelectedColumn]->Alignment == taCenter ||
                NextGrid1->Columns->Item[NextGrid1->SelectedColumn]->Alignment == taRightJustify)
                        btnRightAlignment->Down = true;
        if (btnBold->Down == fsBold)
                NextGrid1->Cell[ACol][ARow]->FontStyle;
        if (btnItalic->Down == fsItalic)
                NextGrid1->Cell[ACol][ARow]->FontStyle;
        btnUnderline->Down = NextGrid1->Cell[ACol][ARow]->FontStyle.Contains(fsUnderline);
        ColorPickerEditor1->SelectedColor = NextGrid1->Cell[ACol][ARow]->Color;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NextGrid1BeforeEdit(TObject *Sender, int ACol, int ARow, bool &Accept)
{
        if ( (ACol == 2 && ARow == 2) || (ACol == 1 && ARow == 3) ) {
                ShowMessage("OnBeforeEditEvent: Editing this cell is disabled.");
                Accept = false;
        }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::HideFocus1Click(TObject  *Sender)
{
        TMenuItem *MnItm = dynamic_cast<TMenuItem *> (Sender);
        if (MnItm->Checked)
                NextGrid1->AppearanceOptions = NextGrid1->AppearanceOptions << aoHideFocus;
        else    NextGrid1->AppearanceOptions = NextGrid1->AppearanceOptions >> aoHideFocus;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::EditCell261Click(TObject  *Sender)
{
        NextGrid1->EditCell(2, 6);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ToolButton21Click(TObject  *Sender)
{
	if (SaveDialog2->Execute())
                NextGrid1->SaveToTextFile(SaveDialog2->FileName);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ToolButton22Click(TObject  *Sender)
{
        if (OpenDialog1->Execute())
                NextGrid1->LoadFromTextFile(OpenDialog1->FileName);
        Application->ProcessMessages();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btnAddClick(TObject  *Sender)
{
        AddRows(100000, true);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button4Click(TObject  *Sender)
{
        AddRows(30000, true);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NextGrid1CellColoring(TObject  *Sender, int ACol, int ARow,
                      TColor &CellColor, TColor &GridColor, TCellState CellState)
{
	if (ACol == 2 && ARow == 2) {
	        NextGrid1->Canvas->Font->Color = clRed;
	        NextGrid1->Canvas->Font->Style = NextGrid1->Canvas->Font->Style << fsBold;
	}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NextGrid1CellClick(TObject *Sender, int  ACol, int ARow)
{
/*        if (ACol == 9) {
                if (NextGrid1->Cells[9][ARow]->AsString == "0")
                        NextGrid1->DeleteRow(ARow);
        }     */
}
//---------------------------------------------------------------------------
void  __fastcall  TForm1::Columns2SortedTrue1Click(TObject *Sender)
{
        NextGrid1->Columns->Item[6]->SortKind = skDescending;
        NextGrid1->Columns->Item[6]->Sorted = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Cell24ColorclRed1Click(TObject  *Sender)
{
        NextGrid1->Cell[2][4]->Color = clRed;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NextGrid1CellFormating(TObject *Sender, int ACol, int ARow,
                       TColor &TextColor, TFontStyles &FontStyle, TCellState CellState)
{
        if (ACol == 5) {
                if (NextGrid1->Cell[5][ARow]->AsInteger < 200) TextColor = clRed;
                if (NextGrid1->Cell[5][ARow]->AsInteger > 1800) TextColor = clBlue;
        }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::urnOnAutoSize1Click(TObject  *Sender)
{
        TMenuItem *FMnItm = dynamic_cast<TMenuItem *> (Sender);
	for (int i = 0; i < NextGrid1->Columns->Count; ++i) {
                if (FMnItm->Checked)
                        NextGrid1->Columns->Item[i]->Options = NextGrid1->Columns->Item[i]->Options << coAutoSize;
                else    NextGrid1->Columns->Item[i]->Options = NextGrid1->Columns->Item[i]->Options >> coAutoSize;
        }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SaveSettingsToINIFile1Click(TObject  *Sender)
{
        NextGrid1->SaveToIni(ExtractFilePath(ParamStr(0))+ "IniFile.ini");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::LoadSettingsFromINIFile1Click(TObject  *Sender)
{
        NextGrid1->LoadFromIni(ExtractFilePath(ParamStr(0))+ "IniFile.ini");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Exit1Click(TObject  *Sender)
{
        Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Print1Click(TObject  *Sender)
{
	if (PrintDialog1->Execute())
                GridPrint1->Print();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Footer2Click(TObject  *Sender)
{
        TMenuItem *FMnItm = dynamic_cast<TMenuItem *> (Sender);
        if (FMnItm->Checked)
                NextGrid1->Options = NextGrid1->Options << goFooter;
        else    NextGrid1->Options = NextGrid1->Options >> goFooter;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Header2Click(TObject  *Sender)
{
        TMenuItem *FMnItm = dynamic_cast<TMenuItem *> (Sender);
        if (FMnItm->Checked)
                NextGrid1->Options = NextGrid1->Options << goHeader;
        else    NextGrid1->Options = NextGrid1->Options >> goHeader;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::InputLine2Click(TObject  *Sender)
{
        TMenuItem *FMnItm = dynamic_cast<TMenuItem *> (Sender);
        if (FMnItm->Checked)
                NextGrid1->Options = NextGrid1->Options  << goInput;
        else    NextGrid1->Options = NextGrid1->Options  >> goInput;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Indicator1Click(TObject  *Sender)
{
        TMenuItem *FMnItm = dynamic_cast<TMenuItem *> (Sender);
        if (FMnItm->Checked)
                NextGrid1->Options = NextGrid1->Options << goIndicator;
        else    NextGrid1->Options = NextGrid1->Options >> goIndicator;

}
//---------------------------------------------------------------------------
void __fastcall TForm1::HideColumnsWithMouse1Click(TObject  *Sender)
{
        TMenuItem *FMnItm = dynamic_cast<TMenuItem *> (Sender);
        if (FMnItm->Checked)
                NextGrid1->Options = NextGrid1->Options << goCanHideColumn;
        else    NextGrid1->Options = NextGrid1->Options >> goCanHideColumn;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::DisableColumnMoving1Click(TObject  *Sender)
{
        TMenuItem *FMnItm = dynamic_cast<TMenuItem *> (Sender);
        if (FMnItm->Checked)
                NextGrid1->Options = NextGrid1->Options << goDisableColumnMoving;
        else    NextGrid1->Options = NextGrid1->Options >> goDisableColumnMoving;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SelectFullRow2Click(TObject  *Sender)
{
        TMenuItem *FMnItm = dynamic_cast<TMenuItem *> (Sender);
        if (FMnItm->Checked)
                NextGrid1->Options = NextGrid1->Options << goSelectFullRow;
        else    NextGrid1->Options = NextGrid1->Options >> goSelectFullRow;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::IndicateSelectedCell1Click(TObject  *Sender)
{
        TMenuItem *FMnItm = dynamic_cast<TMenuItem *> (Sender);
        if (FMnItm->Checked)
                NextGrid1->AppearanceOptions = NextGrid1->AppearanceOptions << aoIndicateSelectedCell;
        else    NextGrid1->AppearanceOptions = NextGrid1->AppearanceOptions >> aoIndicateSelectedCell;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::MultiSelect1Click(TObject  *Sender)
{
        TMenuItem *FMnItm = dynamic_cast<TMenuItem *> (Sender);
        if (FMnItm->Checked)
                NextGrid1->Options = NextGrid1->Options >> goMultiSelect;
        else    NextGrid1->Options = NextGrid1->Options << goMultiSelect;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NextGrid1FooterClick(TObject *Sender, int ACol)
{
        if (ACol == 5) NextGrid1->CalculateFooter();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Search1Click(TObject  *Sender)
{
//        Form3->Show();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btnBoldClick(TObject  *Sender)
{
        if (NextGrid1->CellBounds(NextGrid1->SelectedColumn, NextGrid1->SelectedRow)) {
                TToolButton *TBtn = dynamic_cast<TToolButton *> (Sender);
                if (TBtn->Down)
                        NextGrid1->Cell[NextGrid1->SelectedColumn][NextGrid1->SelectedRow]->FontStyle = NextGrid1->Cell[NextGrid1->SelectedColumn][NextGrid1->SelectedRow]->FontStyle << fsBold;
                else    NextGrid1->Cell[NextGrid1->SelectedColumn][NextGrid1->SelectedRow]->FontStyle = NextGrid1->Cell[NextGrid1->SelectedColumn][NextGrid1->SelectedRow]->FontStyle >> fsBold;
        }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btnItalicClick(TObject  *Sender)
{
        if (NextGrid1->CellBounds(NextGrid1->SelectedColumn, NextGrid1->SelectedRow)) {
                TToolButton *TBtn = dynamic_cast<TToolButton *> (Sender);
                if (TBtn->Down)
                        NextGrid1->Cell[NextGrid1->SelectedColumn][NextGrid1->SelectedRow]->FontStyle = NextGrid1->Cell[NextGrid1->SelectedColumn][NextGrid1->SelectedRow]->FontStyle << fsItalic;
                else    NextGrid1->Cell[NextGrid1->SelectedColumn][NextGrid1->SelectedRow]->FontStyle = NextGrid1->Cell[NextGrid1->SelectedColumn][NextGrid1->SelectedRow]->FontStyle >> fsItalic;
        }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btnUnderlineClick(TObject  *Sender)
{
        if (NextGrid1->CellBounds(NextGrid1->SelectedColumn, NextGrid1->SelectedRow)) {
                TToolButton *TBtn = dynamic_cast<TToolButton *> (Sender);
                if (TBtn->Down)
                        NextGrid1->Cell[NextGrid1->SelectedColumn][NextGrid1->SelectedRow]->FontStyle = NextGrid1->Cell[NextGrid1->SelectedColumn][NextGrid1->SelectedRow]->FontStyle << fsUnderline;
                else    NextGrid1->Cell[NextGrid1->SelectedColumn][NextGrid1->SelectedRow]->FontStyle = NextGrid1->Cell[NextGrid1->SelectedColumn][NextGrid1->SelectedRow]->FontStyle >> fsUnderline;
        }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ColorPickerEditor1Change(TObject  *Sender)
{
        if (NextGrid1->CellBounds(NextGrid1->SelectedColumn, NextGrid1->SelectedRow)) {
                if (ColorPickerEditor1->SelectedColor == clNone)
                        NextGrid1->Cell[NextGrid1->SelectedColumn][NextGrid1->SelectedRow]->Color = Color;
                else    NextGrid1->Cell[NextGrid1->SelectedColumn][NextGrid1->SelectedRow]->Color = ColorPickerEditor1->SelectedColor;
        }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ToolButton23Click(TObject  *Sender)
{
        if (SaveDialog3->Execute()) {
                NextGrid1->SaveToHTML(SaveDialog3->FileName);
        }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NextGrid1EditAccept(TObject *Sender, int ACol, int ARow, WideString Value, bool &Accept)
{
        if (Value == WideString("-1") ) {
                Accept = false;
                ShowMessage("This Value is not accapted");
        }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
        NextGrid1->ApplyEditing();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ReportView1Click(TObject  *Sender)
{
        NextGrid1->GridStyle = gsReport;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SlideView1Click(TObject  *Sender)
{
        NextGrid1->GridStyle = gsSlides;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NextGrid1HeaderClick(TObject *Sender, int ACol)
{
	if (ACol == 0)
                ShowMessage("This column can not be sorted (OnHeaderClick Event).");
}

