I have some text files with records, and I would like to have these
records on a grid. So, some of the records have a code, 1 or 0. If the
code is 1, the check box is selected, otherwise itsn't. I would like, on
my TStringGrid, in one of the column, put a checkBox in place of a text.
It is possible to have a control and how to create it dynamically. In
effect, when I read the table, I don't know the number of lines, and I
don't know how to create several checkBox....
Thank you for your help.
Gabriel Giordano
You could use the InfoPower controls - they have a check box in their DB
Grid.
Alternatively, you might consider using a TCtrlGrid grid instead.
HTH,
Brian
Bedford Bob wrote in message <3770F376...@NoSpam.Com>...
I just wrote such a grid component TSelStringGrid for that exact
purpose. I needed to be able to let the user check the desired grid
rows.
It's an extension of TStringGrid. I might not be allowed to give it
away, but I might be able to arrange a good deal for you (one-time
purchase with full source and no limitations). Let me know if you're
interested! By the way, it's developed for D4. No idea if it works in
older versions.
Kjell
Gabriel,
you don't need true checkbox controls, only the *image* of a checked or
unchecked box, which you then paint into the cell in an OnDrawCell handler
for the grid.
Showing checkboxes in a stringgrid
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
StdCtrls, ExtCtrls, Grids;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
FCheck, FNoCheck: TBitmap;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
If not ( gdFixed In State ) and (aCol = 1) Then Begin
With (Sender As TStringgrid).Canvas Do Begin
brush.color := $E0E0E0;
// checkboxes look better on a non-white background
Fillrect( rect );
If (Sender As TStringgrid).Cell[aCol, aRow] = '1' Then
Draw( (rect.right + rect.left - FCheck.width) div 2,
(rect.bottom + rect.top - FCheck.height) div 2,
FCheck )
Else
Draw( (rect.right + rect.left - FNoCheck.width) div 2,
(rect.bottom + rect.top - FNoCheck.height) div 2,
FNoCheck )
End;
End;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
bmp: TBitmap;
begin
FCheck:= TBitmap.Create;
FNoCheck:= TBitmap.Create;
bmp:= TBitmap.create;
try
bmp.handle := LoadBitmap( 0, PChar(OBM_CHECKBOXES ));
// bmp now has a 4x3 bitmap of divers state images
// used by checkboxes and radiobuttons
With FNoCheck Do Begin
// the first subimage is the unchecked box
width := bmp.width div 4;
height := bmp.height div 3;
canvas.copyrect( canvas.cliprect, bmp.canvas, canvas.cliprect );
End;
With FCheck Do Begin
// the second subimage is the checked box
width := bmp.width div 4;
height := bmp.height div 3;
canvas.copyrect(
canvas.cliprect,
bmp.canvas,
rect( width, 0, 2*width, height ));
End;
finally
bmp.free
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
FNoCheck.Free;
FCheck.Free;
end;
end.
Peter Below (TeamB) 10011...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
what about using TListView instead of TStringList? In D4 (don`t know about
D3) TListView has property CheckBoxes.
With regards,
Jack Sudarev.
> Hello,
>
> I have some text files with records, and I would like to have these
> records on a grid. So, some of the records have a code, 1 or 0. If the
> code is 1, the check box is selected, otherwise itsn't. I would like, on
> my TStringGrid, in one of the column, put a checkBox in place of a text.
> It is possible to have a control and how to create it dynamically. In
> effect, when I read the table, I don't know the number of lines, and I
> don't know how to create several checkBox....