Jump to content

TUniStringGrid onDrawCell - Problem


herculanojs

Recommended Posts

I am facing problematic with the onDrwaCell event of UniStrigGrid. This event is only triggered once when the StringGrid is mounted. After even manipulating the values of the grid this event does not fire any more.

What is the solution to this?

Link to comment
Share on other sites

Build 1.0.0.1424

 

The UniStringGrid is changed in this procedure. Yet by no means ondrawcell is being fired. It is triggered only once when the procedure is first performed.

 

a) Stringgrid tuning procedure

procedure TfrmAgendamento.UpdateCalendar;
var
AYear, AMonth, ADay: Word;
FirstDate: TDateTime;
 ACol,ARow:integer;
begin
     FUpdating := True;
     try
        sgCalendario.ColCount := 7;
        sgCalendario.RowCount := 7;
 
        DecodeDate(FDate, AYear, AMonth, ADay);
        FirstDate := EncodeDate(AYear, AMonth, 1);
        { day of week for 1st of month }
        FMonthOffset := 2 - ((DayOfWeek(FirstDate) - FStartOfWeek + 7) mod 7);
 
        for ACol := 0 to 6 do
        for ARow := 0 to 6 do
            sgCalendario.Cells[ACol,ARow] := GetCellText(Acol,Arow);
 
        sgCalendario.HeaderTitle := IntToStr(day)+' de '+MonthText+'/'+IntToStr(Year)+' ('+formatdatetime('dddd',CalendarDate)+')';
 
        DrawEvents;
        sgCalendario.Repaint;
        Invalidate;
        { trigger OnDateChange and all HookEvents }
        if Assigned(FDateChange) then FDateChange(Self, FDate);
     finally
       FUpdating := False;
     end;
 
end;
 

 

B) OnDrawCell (procedure)

 

procedure TfrmAgendamento.sgCalendarioDrawCell(Sender: TObject; ACol,  ARow: Integer; var Value: string; Attribs: TUniCellAttribs);
var
DayNumStr : string;
wOutStr : String;
wYear : Word;
wMonth : Word;
wDay : Word;
wLeft : Integer;
i,f: integer;
ADate: TDateTime;
begin
     DayNumStr:=CellText[ACol, ARow];
     Attribs.Font.Color  := clBlack;
     Attribs.Color := clWhite;
 
     if ((ACol = 0) or (ACol = 6)) and
        FBlockWeekends and (DayNumStr<>'') and (ARow <> 0) then
       Attribs.Color := BlockedColor;
 
     If (ARow=0) Then
     Begin
          Attribs.Color       := sgCalendario.FixedColor;
          Attribs.Font.Color  := clBlack;
          Attribs.Font.Style  := [fsBold];
     End;
 
     if (FHiliteSunday) And (ACol=0) And (ARow<>0) then
        Attribs.font.color:=clRED;
 
     If (ARow>0) Then
     Begin
          IF DayNumStr<>'' Then
          Begin
               DecodeDate(Now,wYear,wMonth,wDay);
               If (wYear=Year) and (wMonth=Month) and (wDay=StrToInt(DayNumStr)) Then
               Begin
                    Attribs.Font.Style:=Attribs.Font.Style+[fsBold];
                    Attribs.Font.Color := clWhite;
                    Attribs.Color := clNavy;
               End;
          End;
 
          if (Events.Count > 0) and (CellText[ACol, ARow] <> '') then
          begin
               DayNumStr := CellText[ACol, ARow];
 
               i := GetDayEvent(StrToInt(DayNumStr),Month,Year);
               if (i <> -1) and (Events.Count >= I) then
               begin
                    Attribs.Color := clyellow;
                    Attribs.Font.Color := clred;
               end;
          end;
 
     end;
end;
Link to comment
Share on other sites

  • 2 weeks later...

Hi Delphi Developer,

 

  Any update on this as it seems calling Invalidate does not trigger the OnDrawCell after the grid has been initially created?

 

  Build 1413.

Link to comment
Share on other sites

  • 11 months later...
3 minutes ago, Sherzod said:

Hi,

Can you please clarify what problem do you have?

I am facing problematic with the onDrwaCell event of UniStrigGrid. This event is only triggered once when the StringGrid is mounted. After even manipulating the values of the grid this event does not fire any more.

 

What is the solution to this?
Link to comment
Share on other sites

18 minutes ago, Sherzod said:

Está bem

I click on the column and change the value to 1, if the value is already in 1 I put it to 2 and the colors have to change according to the value, but if I click once on the column it changes the value and if I click again in the same column the value remains the same. The unigui does not recognize the second click on the same column, I have to click on another column so that I can click on the other column again.

Exemplo.gif

StringGrid Demo - Copia.rar

Link to comment
Share on other sites

1 hour ago, eduardosuruagy said:

The unigui does not recognize the second click on the same column, I have to click on another column so that I can click on the other column again.

This is normal behavior, because you are using OnSelectCell event

Link to comment
Share on other sites

procedure TMainForm.UniStringGrid1Click(Sender: TObject);
var
  _Value : String;
  grid: TUniStringGrid;
begin
  grid := (Sender as TUniStringGrid);
  with grid do
    if (Row >= 0) then
    begin
      _Value := Cells[Col, Row];

      if _Value = '1' then
        _Value := '2'
      else if _Value = '2' then
        _Value := '1'
      else
        _Value := '1';

      Cells[Col, Row] := _Value;

    end;
end;

 

Link to comment
Share on other sites

22 hours ago, Sherzod said:

procedure TMainForm.UniStringGrid1Click(Sender: TObject);
var
  _Value : String;
  grid: TUniStringGrid;
begin
  grid := (Sender as TUniStringGrid);
  with grid do
    if (Row >= 0) then
    begin
      _Value := Cells[Col, Row];

      if _Value = '1' then
        _Value := '2'
      else if _Value = '2' then
        _Value := '1'
      else
        _Value := '1';

      Cells[Col, Row] := _Value;

    end;
end;

 

Many thanks, it worked !!

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...