Search code examples
c++c++buildervclteechartgantt-chart

Teechart Gantt date in C++


i'm a newbie and i'm working on a C++ VCL project with a StringGrid and a GanttChart. What i want to do is to "update" the gantt bar automatically once a new data is entered into the StringGrid.

What i do first is to create a chart with bars with this command:

TGanttSeries *Series1;
 int i = 0;

Series1 = new TGanttSeries(this);
Series1->AddGantt(StrToDate(StringGridEd1->Cells[4][1]),StrToDate(StringGridEd1->Cells[5][1]), i,"Task"+IntToStr(i));
Series1->ParentChart = Chart1;

That's perfect for creating a chart but how do i update the gantt's bar date so the bar automatically resize itself? For example if the user enter 1 day, the gantt bar display only 1 day and when the user enter 5 day the gantt bar automatically "resize" itself from 1 to 5 days.

Is there any function or properties which can do this for me?


Solution

  • I've just replied you at Steema Software official forum (here).
    I'm copying the answer here:

    If I understand it correctly, you can update your series StartValues/EndValues at the StringGrid1SetEditText event. Ie:

    TGanttSeries *Series1;
    
    void __fastcall TForm1::FormCreate(TObject *Sender)
    {
      StringGrid1->ColCount = 6;
      StringGrid1->RowCount = 2;
      StringGrid1->Cells[4][1] = "01/01/2016";
      StringGrid1->Cells[5][1] = "02/01/2016";
      StringGrid1->Options << goEditing;
    
      int i = 0;
    
      Series1 = new TGanttSeries(this);
      Series1->AddGantt(StrToDate(StringGrid1->Cells[4][1]),StrToDate(StringGrid1->Cells[5][1]), i,"Task"+IntToStr(i));
      Series1->ParentChart = Chart1;
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::StringGrid1SetEditText(TObject *Sender, int ACol, int ARow,
              const UnicodeString Value)
    {
      TDateTime tmp;
    
      if ((ACol==4) || (ACol==5)) {
        if (TryStrToDate(StringGrid1->Cells[ACol][ARow], tmp)) {
          if (ACol==4) {
            Series1->StartValues->Value[ARow-1] = tmp;
            Series1->StartValues->Modified = true;
          }
          else {
            Series1->EndValues->Value[ARow-1] = tmp;
            Series1->EndValues->Modified = true;
          }
        }
      }
    }