One way to show a checkmark in a Boolean field in Delphi's DBGrid is to use a TDBComboBox control instead of a TDBCheckBox control in the grid's column editor. Set the combobox's Items property to "Yes" and "No", and its Style property to "csDropDownList". Then, use the OnDrawColumnCell event of the grid to draw a checkmark symbol in the cell when the field value is True. Here's an example code:
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); var CheckRect: TRect; begin if Column.Field.DataType = ftBoolean then begin CheckRect := Rect; InflateRect(CheckRect, -2, -2); DrawFrameControl(DBGrid1.Canvas.Handle, CheckRect, DFCBUTTON, DFCSBUTTONCHECK or ( Ord(Column.Field.AsBoolean) * DFCS_CHECKED ) ); end else DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State); end;
This code checks if the column's field is a Boolean type, and if so, it draws a checkmark or an unchecked box in the column cell depending on its value. The InflateRect function is used to create a smaller rectangle inside the cell's rectangle, where the checkmark will be drawn. The DrawFrameControl function is a Windows API function that draws a checkbox frame with a checkmark or an unchecked box, depending on the DFCS_CHECKED flag passed to it.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2022-03-26 11:00:00 +0000
Seen: 19 times
Last updated: Mar 10 '23
Can the new position of a dynamically shifted control be saved in Delphi?
In Delphi, what is the method for formatting a Unix timestamp?
How can memory leaks in UnicodeStrings be addressed in Delphi?
How can POST data be handled in the OnNavigate event when using Delphi TEdgeBrowser?
How can RxLib be used together with Delphi 11?
In Delphi, what is the method to obtain a numeric variant property?
How to display a form or a "please wait" panel while executing a task in FMX Delphi 10.2?