cz3ch
cz3ch

Reputation: 409

Add a row to a TDBGrid

I've created a TGroupBox containing 5 TEdit, a TButton and a TDBGrid. I would like to append the content of the five TEdits in the last row of the TDBGrid when I click on the TButton.

TDBGrid

The problem is that I don't even know where to start and I can't find any correct documentation or example on the internet. Any idea? on where to start to achieve this?

Upvotes: 0

Views: 171

Answers (1)

cz3ch
cz3ch

Reputation: 409

TDBGrid is used to link a database. To manually implement a Table simply use TStringGrid instead. here is a piece of code for what I sought :

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  if((Edit1->Text!="")&&(Edit2->Text!="")&&(Edit3->Text!=""))
  {
    StringGrid1->RowCount=StringGrid1->RowCount+1;
    StringGrid1->Cells[0][StringGrid1->RowCount-1]=StringGrid1->RowCount-1;
    StringGrid1->Cells[1][StringGrid1->RowCount-1]=Edit1->Text;
    StringGrid1->Cells[2][StringGrid1->RowCount-1]=Edit2->Text;
    StringGrid1->Cells[3][StringGrid1->RowCount-1]=Edit3->Text;
    StringGrid1->Cells[4][StringGrid1->RowCount-1]=Edit4->Text;
    Edit1->Text="";
    Edit2->Text="";
    Edit3->Text="";
    Edit4->Text="";
  }
}

Upvotes: 1

Related Questions