I'm a newbie in C++ Builder and really need some help. In my work, we have to use C++ Builder and I can't find very much documentation about it.
What I want to do is to insert a new row with some data in each column each time the user press the Insert key. There are 20 rows in total in my TGrid: 1 TCheckColumn
and 19 TStringColumn
.
I don't know how to do it exactly. First, here is the code I already wrote when someone enter the insert key:
void __fastcall TForm2::Grid1KeyDown(TObject *Sender, WORD &Key, System::WideChar &KeyChar,
TShiftState Shift)
{
switch(Key)
{
case VK_INSERT:
if(Grid1->RowCount>MAXTask){}else
{
Label1->Text = "number Task: "+IntToStr(++nmbertask);
Grid1->RowCount++;
}
break;
}
}
Here is the Grid1GetValue()
and Grid1SetValue()
code:
void __fastcall TForm2::Grid1GetValue(TObject *Sender, const int Col, const int Row,
TValue &Value)
{
switch(Col)
{
case 0:
Value = A[Col][Row]; break;
case 1:
Value = A[Col][Row]; break;
case 2:
Value = A[Col][Row]; break;
case 3:
Value = A[Col][Row]; break;
case 4:
Value = A[Col][Row]; break;
case 5:
Value = A[Col][Row]; break;
case 6:
Value = A[Col][Row]; break;
case 7:
Value = A[Col][Row]; break;
case 8:
Value = A[Col][Row]; break;
case 9:
Value = A[Col][Row];break;
case 10:
Value = A[Col][Row];break;
case 11:
Value = A[Col][Row];break;
case 12:
Value = A[Col][Row];break;
case 13:
Value = A[Col][Row];break;
case 14:
Value = A[Col][Row];break;
case 15:
Value = A[Col][Row];break;
case 16:
Value = A[Col][Row];break;
case 17:
Value = A[Col][Row];break;
case 18:
Value = A[Col][Row]; break;
case 19:
Value = A[Col][Row];break;
}
}
void __fastcall TForm2::Grid1SetValue(TObject *Sender, const int Col, const int Row,
const TValue &Value)
{
switch(Col)
{
case 0:
A[Col][Row] = Value; break;
case 1:
A[Col][Row] = Value; break;
case 2:
A[Col][Row] = Value; break;
case 3:
A[Col][Row] = Value; break;
case 4:
A[Col][Row] = Value; break;
case 5:
A[Col][Row] = Value; break;
case 6:
A[Col][Row] = Value; break;
case 7:
A[Col][Row] = Value; break;
case 8:
A[Col][Row] = Value; break;
case 9:
A[Col][Row] = Value; break;
case 10:
A[Col][Row] = Value; break;
case 11:
A[Col][Row] = Value; break;
case 12:
A[Col][Row] = Value; break;
case 13:
A[Col][Row] = Value; break;
case 14:
A[Col][Row] = Value; break;
case 15:
A[Col][Row] = Value; break;
case 16:
A[Col][Row] = Value; break;
case 17:
A[Col][Row] = Value; break;
case 18:
A[Col][Row] = Value; break;
case 19:
A[Col][Row] = Value; break;
}
}
This is what I've done so far. I've never developed in C++ Builder, so can you help me please? I'm not really looking for a written solution, I'm really looking for an indication of where to look for a solution.
If I'm not clear, please indicate it so I can give more information. If you also have a good site with good documentation about C++ Builder, please indicate it to me. English is not my native language but I will do my best.
You can find the TGrid
documentation on Embarcadero's DocWiki. Look at the 'Methods' page to figure out how to insert and remove elements in your TGrid
. There are two methods that can help you: InsertComponent()
and `InsertObject().
Also, in your Grid1GetValue()
and Grid1SetValue()
methods, you are using a switch
statement. In all those cases you are doing the same job :
Value = A[Col][Row];break;
So, instead of using a switch
, you can simply call one time Value = A[Col][Row];
and it will do the same result.
I hope my answer can help you. At least I answered what I understood from your question.