I want to put a TCheckBox
inside a TStringGrid
in Delphi in every cell of certain column. I'm using Delphi XE.
相关问题
- Is there a Delphi 5 component that can handle .png
- Is there a way to install Delphi 2010 on Windows 2
- Is TWebBrowser dependant on IE version?
- iOS objective-c object: When to use release and wh
- DBGrid - How to set an individual background color
相关文章
- Best way to implement MVVM bindings (View <-> V
- Windows EventLog: How fast are operations with it?
- How to force Delphi compiler to display all hints
- Coloring cell background on firemonkey stringgrid
- HelpInsight documentation in Delphi 2007
- Can RTTI interrogate types from project code at de
- What specifically causes EPrivilege to be raised?
- Equivalent to designer guidelines in code
You should draw your own checkboxes, preferably using visual themes, if enabled. This is a simple sketch of how to do that:
Of course, in a real scenario, the
Checked
array is not a constant, and you might wish to save thes
metrics andh
theme handle between cell painting events. But the principle is here.What is missing here is a function to alter the state of the checkboxes. You will probably want to toggle the state in an
OnClick
handler. If you are really serious, you'll also wish to respond to the motion of the mouse, and display the mouse hover effect on the checkboxes if themes are available.EDIT by bluish: To toggle checkbox state, this answer explains how you can use
Invalidate
method.Don't try to place an actual
TCheckBox
control inside aTStringGrid
. Use the grid'sOnDrawCell
event with the Win32 APIDrawFrameControl()
function instead, to draw an image of a CheckBox control inside each cell as needed. You can use theOnClick/OnMouse...
events with the grid'sObjects[][]
property to keep track of each cell's checked state as needed. I find this is a lot easier to manage, sinceTStringGrid
was not designed to host real controls.I use a virtual grid called ExGridView by Roman Mochalov, that supports checkboxes.
My own modified fork of GridView, ported for Unicode etc, named TExGridView, instead of TGridView, and with a demo of checkboxes is on bitbucket here as /wpostma/exgridview.
The ExGridView component has a Checkbox property in the property inspector which must be set true, Then you must set up your Column properties so that the Column has a checkbox type set to checkbox or radio button. Then you must implement the GetCheckState event callback. See the demo included on the bitbucket project.
The original source for this code was here but it's not buildable on recent versions. My bitbucket version is tested and working with Delphi 2007, 2009, and all versions up to date as of 2016 (Delphi 10 Seattle).