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

#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 "NxEdit"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
        NextGrid1->AddRow(3);
        NextGrid1->Cell[0][0]->AsString = "Mike";
        NextGrid1->Cell[0][1]->AsString = "Jack";
        NextGrid1->Cell[0][2]->AsString = "Dona";

        NextGrid1->Cell[1][0]->AsFloat = 5.63;
        NextGrid1->Cell[1][1]->AsFloat = 12.77;
        NextGrid1->Cell[1][2]->AsFloat = 7.2;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::btnRightClick(TObject *Sender)
{
        NextGrid1->Columns->Item[NextGrid1->SelectedColumn]->Alignment = taRightJustify;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::btnLeftClick(TObject *Sender)
{
        NextGrid1->Columns->Item[NextGrid1->SelectedColumn]->Alignment = taLeftJustify;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::btnCenterClick(TObject *Sender)
{
        NextGrid1->Columns->Item[NextGrid1->SelectedColumn]->Alignment = taCenter;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::NextGrid1SelectCell(TObject *Sender, int ACol,
      int ARow)
{
        switch(NextGrid1->Columns->Item[NextGrid1->SelectedColumn]->Alignment)
        {
                case taLeftJustify:
                {
                        btnLeft->Down = True;
                        break;
                }
                case taCenter:
                {
                        btnCenter->Down = True;
                        break;
                }
                case taRightJustify:
                {
                        btnRight->Down = True;
                        break;
                }
        }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::cmbColorSelect(TObject *Sender)
{
/*      Because each cell having own color, setting Column.Color will NOT
        have effect on existing cells. We need to use loop to set color
        for them again */
        
        for(int i = 0; i < NextGrid1->RowCount; i++)
        {
                NextGrid1->Cell[NextGrid1->SelectedColumn][i]->Color = cmbColor->SelectedColor;
        }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
        NextGrid1->BestFitColumn(NextGrid1->SelectedColumn, bfCells);

/*
        bfCells - Fit to largest cell content
        bfHeader - Fit to header content width
        bfBoth - Fit to cell or header (to which one is wider)
*/
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button3Click(TObject *Sender)
{
        NextGrid1->CalculateFooter();        
}
//---------------------------------------------------------------------------

