FNCDataGrid Checkboxes - OnGetCellLayout

Hi,

I made a unit to handle all things FNCDataGrid.
When I assign my custom OnGetCellLayout handler to the DataGrid, I get an Access Violation.

The reason I want to this is because I want to add checkboxes to certain columns.
The problem is that if I make a specific column a "CheckboxColumn", it also adds the checkbox to the header row.
And, even if I put the "ReadOnly" property to "true", it's still possible to (un)check the checkbox and the it displays the text TRUE and FALSE. (For this last thing I found a solution here somewhere)

If there is a better way to handle the checkboxes, a different solution is greatly appreciated!

uDataGridRoutines.pas (9.7 KB)

Can you put together a sample?

Of course.
Here you go.

If I just add 15 rows, everything goes right.
But when I try to do that after the FormatGrid, something goes wrong.
The "FormatGrid" routine works without assigning my custom OnGetCellLayout handler.
From the moment the custom event handler is assigned, I cannot add rows.

FNCDataGrid.zip (12.8 KB)

The OnGetCellLayoutHandler wrongly assumes the Sender is of type TTMSFNCDataGrid, it is actually of type TTMSFNCDataGridRenderer.

oh, ok.
Is there something I can do about it?

Is there maybe a better way to handle the checkboxes and read-only behaviour?

You can keep the code, just typecast Sender to TTMSFNCDataGridRenderer, and use GetParentHost to access the main grid. It's unclear why you destroy and re-add a new reference, isn't it sufficient to just type-cast the control and toggle the enabled property? Also, you might want to add this code in the OnGetCellProperties event instead of the OnGetCellLayout

I changed the way it works.
Now I use CheckBoxColumns and dynamically remove the checkbox in the fixed row.
I also found a way to check an uncheck the checkboxes.
However I need tot this every time I fill the grid with data.
I'm wondering if there's not an easier way to do this and have this handled in an event handler.

Also, when I access the Booleans, it returns 0 for false and -1 for true.
A bit strange, but if that's the way it works, than it's ok. Just something to remember...

Here's also the new source-code.
FNCDataGrid.zip (14.2 KB)

I noticed the Boolean helper .ToString isn't actually very helpful. I suggest to use the following code instead.

BoolToStr(grDG.Booleans[2, i], True)

If you have a data checkbox (gcitDataCheckbox) set at designtime, it's hooked automatically to the cell value. By default, it uses the BooleanTrueValue & BooleanFalseValue properties at column binding level (Columns.Binding.BooleanTrueValue, Columns.Binding.BooleanFalseValue). You can then leave out the SetCheckboxValues routine. It can be a choice to combine this with a custom cell as well. Included is a sample modified based on your code.
FNCDataGrid_Modified.zip (85.7 KB)

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.