I'm loading a database table into a grid. I know the default for boolean values is a checkbox. I want to set a value as a string into the cell based on the boolean value and not display a checkbox. I've tried several events including load cell data but can't get it to work.
Any ideas greatly appreciated
You can use the following approach but since the connection with a Boolean field is lost you'll only be able to use this code for display only, not updating. This will involve more code to make sure the Boolean field is mapped to a string value:
TTMSFNCCustomCheckGridCell = class(TTMSFNCCheckGridCell)
public
function GetControlWidth: Single; override;
function GetControlHeight: Single; override;
end;
...
procedure TForm130.TMSFNCGrid1GetCellClass(Sender: TObject; ACol, ARow: Integer;
var CellClassType: TTMSFNCGridCellClass);
begin
if CellClassType = TTMSFNCCheckGridCell then
CellClassType := TTMSFNCCustomCheckGridCell;
end;
procedure TForm130.TMSFNCGrid1GetCellProperties(Sender: TObject; ACol,
ARow: Integer; Cell: TTMSFNCGridCell);
begin
if Cell is TTMSFNCCustomCheckGridCell then
begin
(Cell as TTMSFNCCustomCheckGridCell).ControlStretched := False;
(Cell as TTMSFNCCustomCheckGridCell).Text := BoolToStr((Cell as TTMSFNCCheckGridCell).Checked, True);
end;
end;
{ TTMSFNCCustomCheckGridCell }
function TTMSFNCCustomCheckGridCell.GetControlHeight: Single;
begin
Result := 0;
end;
function TTMSFNCCustomCheckGridCell.GetControlWidth: Single;
begin
Result := 0;
end;
Thanks this is a good start. Since I'm using Firemonkey, I changed the FNC references to FMX and GetControl is a TControl so I assigned it nil. However, now I get the text in the cell along with the checkbox
I think I got it, I just hid the checkbox:
procedure TfmMyForm.TMSFMXLiveGridBindSourceDB1GetCellProperties(
Sender: TObject; ACol, ARow: Integer; Cell: TFmxObject);
begin
inherited;
if Cell is TTMSFMXCustomCheckGridCell then
begin
(Cell as TTMSFMXCheckGridCell).checkbox.Visible := false;
if (Cell as TTMSFMXCheckGridCell).checkbox.IsCheckedProg then
(Cell as TTMSFMXCustomCheckGridCell).Text := 'Active'
else
(Cell as TTMSFMXCustomCheckGridCell).Text := 'InActive'
end;
end;
Thanks for the help
My apologies and thank you for the update. I overlooked that you were using FMX instead of FNC