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

#include <vcl.h>
#pragma hdrstop

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

void __fastcall TForm1::Button1Click(TObject *Sender)
{
/*
        We will add one TextColumn ( __classid(TNxTextColumn) ) and function will return pointer to this column,
        so we may set Header->Caption then.

        1) We have declared new pointer TNxTextColumn *ANewColumn.
        2) Because we are using typecasting (TNxTextColumn*), we are able to set TextColumn-only properties
                such as TextAfter, TextBefore.

        TNxTextColumn may be changed to desire column type (TNxNumberColumn, TNxDateColumn...)
*/
        TNxTextColumn *ANewColumn = (TNxTextColumn*)NextGrid1->Columns->Add(__classid(TNxTextColumn));
        ANewColumn->Header->Caption = "Text Column";
        ANewColumn->Width = 70;
        ANewColumn->TextAfter = " (TextAfter)"; // TextColumn-only property

/*
        1) If we only need to add desired column, and set property which exist in every column type, we may write:

        TNxCustomColumn *ANewColumn = NextGrid1->Columns->Add(__classid(TNxTextColumn));

        2) Or, to simply add a column:

        NextGrid1->Columns->Add(__classid(TNxTextColumn));
*/
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button2Click(TObject *Sender)
{
        switch(cmbColumnType->ItemIndex)
        {
                case 0:
                {
                        NextGrid1->Columns->Add(__classid(TNxDateColumn));
                        break;
                }
                case 1:
                {
                        TNxCustomColumn *AMemoColumn = NextGrid1->Columns->Add(__classid(TNxMemoColumn));
                        AMemoColumn->Options = AMemoColumn->Options << coEditing;
                        break;
                }
                case 2:
                {
                        // Because we need properties located in inherited class TNxNumberColumn, we need to use typecasting
                        TNxNumberColumn *ANumberColumn = (TNxNumberColumn*)NextGrid1->Columns->Add(__classid(TNxNumberColumn));
                        ANumberColumn->Options = ANumberColumn->Options << coEditing;

                        // Number Column specific properties
                        ANumberColumn->Max = 20;
                        ANumberColumn->Increment = 0.5;
                        ANumberColumn->Precision = 2; // Edit precision
                        ANumberColumn->TextAfter = " USD";
                        break;
                }
                case 3:
                {
                        TNxProgressColumn *AProgressColumn = (TNxProgressColumn*)NextGrid1->Columns->Add(__classid(TNxProgressColumn));

                        // Progress Column specific properties
                        AProgressColumn->ShowText = true;
                        break;
                }
        }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
        NextGrid1->AddRow(5);
        cmbColumnType->ItemIndex = 0;       
}
//---------------------------------------------------------------------------
