Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 8 of 8 total
Thread Dynamically added tgrid columns and oncellupdate event
Thu, Mar 14 2019 6:07 AMPermanent Link

Huseyin Aliz

myBiss ApS

Avatar

Hi All,

I am using different datasets for same grid, and for this i am removing
and adding columns when needed, following are my adding method:

AGrid.DataSet := ADataSet;
 for i := 0 to ADataSet.ColumnCount -1 do begin
   col := AGrid.NewColumn;
   col.DataColumn := ADataSet.columns[i].Name;
   col.Header.Caption := ADataSet.columns[i].Name;
   col.Font.Name := 'Arial';
   col.Font.Size := 14;
   col.Font.Color := clBlack;
 end;

I want to color every second row with different colour and it works when
column are static defined and i am using oncellupdate for his purpose.
Now when adding runtime columns i cannot make oncellupdate to happen.

This is a method i try with (GridColumnxCellUpdate should allways work
as it starts with 0?)

procedure TmyForm.GridColumn0CellUpdate(Sender: TObject; ACell: TGridCell);
begin
SetUpCells(ACell);
end;

And SetUpCells procedure:

procedure TmyForm.SetupCells(ACell: TGridCell);
begin
     if (ACell.index mod 2=0) and
(SameText(ACell.InterfaceState,NORMAL_STATE_NAME)) and (ACell.Index
<>    RapportGrid.RowIndex) then begin
     ACell.Font.Size := 14;
     ACell.Font.Color := clBlack;
     ACell.Background.Fill.Color := clWhite;
     end
     else if (ACell.Index <> RapportGrid.RowIndex) and
(SameText(ACell.InterfaceState,NORMAL_STATE_NAME)) then
     begin
     ACell.Font.Size := 14;
     ACell.Font.Color := clBlack;
     ACell.Background.Fill.Color:=clWhiteSmoke;
     end;
     if (ACell.Index = RapportGrid.RowIndex) and
(SameText(ACell.InterfaceState,BOTH_STATE_NAME)) then begin
     ACell.Font.Size := 14;
     ACell.Font.Color := clWhite;
     ACell.Background.Fill.Color := clRed;
     end;
end;

Am I missing something here, maybe some kind of event assigning somewhere?

Sorry for the long post, and thanks in advance.
Huseyin
Thu, Mar 21 2019 11:36 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Huseyin,

<< I am using different datasets for same grid, and for this i am removing and adding columns when needed, following are my adding method:

I want to color every second row with different colour and it works when column are static defined and i am using oncellupdate for his purpose. Now when adding runtime columns i cannot make oncellupdate to happen. >>

Are you assigning the event handler to each grid column's OnCellUpdate event property ?

https://www.elevatesoft.com/manual?action=viewevent&id=ewb2&comp=TGridColumn&event=OnCellUpdate

Tim Young
Elevate Software
www.elevatesoft.com
Thu, Mar 21 2019 12:07 PMPermanent Link

Huseyin Aliz

myBiss ApS

Avatar

Tim,

I usually know what the grid contains of dataset and datacolumns and use
oncellupdate in every column to do the task. In this case the grid
columns are dynamically populated from 2 different datasets with
different fields Smile

Regards,
Huseyin

Den 21-03-2019 kl. 16:36 skrev Tim Young [Elevate Software]:
> Huseyin,
>
> << I am using different datasets for same grid, and for this i am removing and adding columns when needed, following are my adding method:
>
> I want to color every second row with different colour and it works when column are static defined and i am using oncellupdate for his purpose. Now when adding runtime columns i cannot make oncellupdate to happen. >>
>
> Are you assigning the event handler to each grid column's OnCellUpdate event property ?
>
> https://www.elevatesoft.com/manual?action=viewevent&id=ewb2&comp=TGridColumn&event=OnCellUpdate
>
> Tim Young
> Elevate Software
> www.elevatesoft.com
>
Thu, Mar 21 2019 12:57 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Huseyin,

<< I usually know what the grid contains of dataset and datacolumns and use oncellupdate in every column to do the task. In this case the grid columns are dynamically populated from 2 different datasets with different fields Smile>>

That's fine, but are you setting the OnCellUpdate event handler ?  Without doing that, the event handler won't get triggered for a given grid column.

Tim Young
Elevate Software
www.elevatesoft.com
Thu, Mar 21 2019 1:04 PMPermanent Link

Walter Matte

Tactical Business Corporation



Grid.DataSet := ADataSet;
for i := 0 to ADataSet.ColumnCount -1 do
begin
  col := AGrid.NewColumn;
  col.DataColumn := ADataSet.columns[i].Name;
  col.Header.Caption := ADataSet.columns[i].Name;
  col.Font.Name := 'Arial';
  col.Font.Size := 14;
  col.Font.Color := clBlack;

 col.OnCellUpdate :=  MyCellUpdate;         // <<<<<<<<<<<<<<<<<<<<<<<<<<
end;
Thu, Mar 21 2019 4:23 PMPermanent Link

Huseyin Aliz

myBiss ApS

Avatar

Thanks for the hint Walter, works great Smile

Regards,
Huseyin

Den 21-03-2019 kl. 18:04 skrev Walter Matte:
> Grid.DataSet := ADataSet;
> for i := 0 to ADataSet.ColumnCount -1 do
> begin
>     col := AGrid.NewColumn;
>     col.DataColumn := ADataSet.columns[i].Name;
>     col.Header.Caption := ADataSet.columns[i].Name;
>     col.Font.Name := 'Arial';
>     col.Font.Size := 14;
>     col.Font.Color := clBlack;
>
>    col.OnCellUpdate :=  MyCellUpdate;         // <<<<<<<<<<<<<<<<<<<<<<<<<<
> end;
>
Thu, Mar 21 2019 4:24 PMPermanent Link

Huseyin Aliz

myBiss ApS

Avatar

Tim,

Walter was so kind with a hint, now it's working Smile

Regards,
Huseyin

Den 21-03-2019 kl. 17:57 skrev Tim Young [Elevate Software]:
> Huseyin,
>
> << I usually know what the grid contains of dataset and datacolumns and use oncellupdate in every column to do the task. In this case the grid columns are dynamically populated from 2 different datasets with different fields Smile>>
>
> That's fine, but are you setting the OnCellUpdate event handler ?  Without doing that, the event handler won't get triggered for a given grid column.
>
> Tim Young
> Elevate Software
> www.elevatesoft.com
>
Fri, Mar 22 2019 4:29 AMPermanent Link

Walter Matte

Tactical Business Corporation

I can't take credit - Tim asked if you had assigned the event - I just demonstrated how!

I am glad it is working!!! That always feels good.

Walter
Image