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

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "NxColumnClasses"
#pragma link "NxColumns"
#pragma link "NxCustomGrid"
#pragma link "NxCustomGridControl"
#pragma link "NxGrid"
#pragma link "NxScrollControl"
#pragma link "NxColumnClasses"
#pragma link "NxColumns"
#pragma link "NxCustomGrid"
#pragma link "NxCustomGridControl"
#pragma link "NxGrid"
#pragma link "NxScrollControl"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)
{
// -------- Fill cells ------
  NextGrid1->AddRow(5);
  NextGrid1->Cell[0][0]->AsString = "TextBox";
  NextGrid1->Cell[1][0]->AsString = "sample";

  NextGrid1->Cell[0][1]->AsString = "ComboBox";
  NextGrid1->Cell[1][1]->AsString = "sample";

  NextGrid1->Cell[0][2]->AsString = "SpinEdit";
  NextGrid1->Cell[1][2]->AsString = "0";

  NextGrid1->Cell[0][3]->AsString = "ButtonEdit";
  NextGrid1->Cell[1][3]->AsString = "test";

  NextGrid1->Cell[0][4]->AsString = "DatePicker";
  NextGrid1->Cell[1][4]->AsDateTime = Today();

  NextGrid1->Cell[2][2]->AsString = "Sample Cell";
}
//---------------------------------------------------------------------------

void __fastcall TForm1::NextGrid1BeforeEdit(TObject *Sender, int ACol,
      int ARow, bool &Accept)
{
        TNxEdit *InplaceEditor;

// ---------- Set another InplaceEditor based on a ARow param ----------

        switch (ARow)
        {
                case 0:
                {
                        InplaceEditor = new TNxEdit(this);
                        break;
                }
                case 1:
                {
                        InplaceEditor = new TNxComboBox(this);
                        // Typecast InplaceEditor as TNxComboBox to use Items property
                        TNxComboBox *ACombo = (TNxComboBox*)InplaceEditor;
                        ACombo->Items->Add("Item 0");
                        ACombo->Items->Add("Item 1");
                        ACombo->Items->Add("Item 2");
                        break;
                }
                case 2:
                {
                        InplaceEditor = new TNxSpinEdit(this);
                        break;
                }
                case 3:
                {
                        InplaceEditor = new TNxButtonEdit(this);
                        TNxButtonEdit *AButtonEdit = (TNxButtonEdit*)InplaceEditor;
                        AButtonEdit->OnButtonClick = DoButtonClick;
                        break;
                }
                case 4:
                {
                        InplaceEditor = new TNxDatePicker(this);
                        break;
                }
        }

// ---------- Customize InplaceEditor ----------
        InplaceEditor->Hide();
        InplaceEditor->BorderStyle = bsNone;
        InplaceEditor->EditMargins->Left = 1;

// ---------- Attach InplaceEditor ----------
        NextGrid1->Columns->Item[1]->InplaceEdit = InplaceEditor;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::DoButtonClick(TObject *Sender)
{
        ShowMessage("Button Click!");
}
//---------------------------------------------------------------------------

void __fastcall TForm1::NextGrid1EditExit(TObject *Sender)
{
        TNxCustomEdit *InplaceEditor;
        InplaceEditor = NextGrid1->Columns->Item[1]->InplaceEdit;
        delete InplaceEditor;
}
//---------------------------------------------------------------------------

