有没有带checkbox列的stringgrid? 有控件吗?(20分)

  • 主题发起人 主题发起人 analyst
  • 开始时间 开始时间
A

analyst

Unregistered / Unconfirmed
GUEST, unregistred user!
有没有带checkbox列的stringgrid? 有控件吗?
 
DBGridEh中带有checkbox,设置一下就可以了
 
ADVStringGrid里面也带这个功能。
 
用advstringgrid这个问题就解决了。
 
advstringgrid1.AddCheckBox(0,advstringgrid1.row,false,true);
 
自己画,在private定义两个TBitmap
private
FCheck, FNoCheck : TBitmap;
表单FormCreate时
FCheck := TBitmap.Create;
FNoCheck := TBitmap.Create;
With FNoCheckdo
begin
Width := 13;
Height := 13;
Canvas.Pen.Color := clBlack;
Canvas.MoveTo(0, 0);
Canvas.LineTo(12, 0);
Canvas.LineTo(12, 12);
Canvas.LineTo(0, 12);
Canvas.LineTo(0, 0);
Canvas.MoveTo(1, 1);
Canvas.LineTo(11, 1);
Canvas.LineTo(11, 11);
Canvas.LineTo(1, 11);
Canvas.LineTo(1, 1);
end;
With FCheckdo
begin
Width := 13;
Height := 13;
Canvas.CopyRect(Canvas.ClipRect, FNoCheck.Canvas, Rect(0, 0, Width, Height));
Canvas.Pen.Color := clBlack;
for i:=3 to 5do
begin
Canvas.MoveTo(i, i+2);
Canvas.LineTo(i, i+5);
end;
for i:=6 to 9do
begin
Canvas.MoveTo(i, 12-i);
Canvas.LineTo(i, 15-i);
end;
end;

procedure TForm_databakup.TableListGridDrawCell(Sender: TObject;
ACol,
ARow: Integer;
Rect: TRect;
State: TGridDrawState);
var
pGrid : ^TStringGrid;
Area : TRect;
calign : DWORD;
begin
pGrid := @Sender;
if not (gdFixed in State) then
if ARow<(pGrid^.RowCount-1) then
with TStringGrid(Sender).Canvas do
begin
if ACol=0 then
begin
//要显示例的索引
brush.Color:=clWindow;
FillRect(Rect);
if pGrid.Cells[ACol,ARow]='yes' 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 - FCheck.width) div 2,(rect.bottom + rect.top-FCheck.height) div 2, FNoCheck );
end;
end;
pGrid^.Canvas.Font.Color := pGrid^.Font.Color;
if ARow>0 then
begin
if ARow=pGrid^.Row then
pGrid^.Canvas.Brush.Color := clMoneyGreen
else
pGrid^.Canvas.Brush.Color := pGrid^.Color;
//if ACol=4 then
pGrid^.Canvas.Font.Color := clMedGray;
//序号,用灰色
if ARow=(pGrid^.RowCount-1) then
pGrid^.Canvas.Brush.Color := RGB(220,220,220);
if pGrid.Rows[ARow][2]<>pGrid.Rows[ARow][3] then
pGrid^.Canvas.Brush.Color := RGB(242,242,242);
end;
if (ACol>0)or(ARow=0)or(ARow=(pGrid^.RowCount-1)) then
if hds[ACol].width >0 then
with pGrid^do
begin
Canvas.FillRect(Rect);
Area:= Rect;
InflateRect(Area, -1, -1);
Area.Right := Area.Right - 3;
Area.Left := Area.Left + 2;
Area.Top := Area.Top + 1;
calign:=hds[ACol].align;
if ARow=0 then
calign:= DT_CENTER;
DrawText(Canvas.Handle, PChar(Cells[ACol,ARow]), Length(Cells[ACol, ARow]), Area, calign);
end;

end;
 
procedure TForm_databakup.TableListGridMouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
var
MouseDown_Pos : TGridCoord;
pGrid : ^TStringGrid;
begin
pGrid := @Sender;
if Button = mbLeft then
begin
MouseDown_Pos:=pGrid.MouseCoord(X, Y);
if (MouseDown_Pos.Y>0)and(MouseDown_Pos.Y<pGrid.RowCount) then
begin
pGrid.Row := MouseDown_Pos.Y;
if (MouseDown_Pos.Y>0)and(MouseDown_Pos.X=0)and(pGrid.Row<(pGrid.RowCount-1)) then
begin
if pGrid.Cells[pGrid.col, pGrid.row]='yes' then
pGrid.Cells[pGrid.col, pGrid.row]:='no'
else
pGrid.Cells[pGrid.col, pGrid.row]:='yes';
end;
end;
end;
end;
 
procedure Tfrmclientquit.FormCreate(Sender: TObject);
var
bmp:TBitmap;
mychild:Ttreenode;
begin
ischange:=false;
FCheck:= TBitmap.Create;
FNoCheck:= TBitmap.Create;
bmp:= TBitmap.create;
try
bmp.handle := LoadBitmap( 0, PChar(OBM_CHECKBOXES ));
With FNoCheckdo
begin
width := bmp.width div 4;
height := bmp.height div 3;
canvas.copyrect( canvas.cliprect, bmp.canvas, canvas.cliprect );
end;
With FCheckdo
begin
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 Tfrmclientquit.listgridDrawCell(Sender: TObject;
ACol,
ARow: Integer;
Rect: TRect;
State: TGridDrawState);
var
dx,dy:byte;
begin
//控制标题栏的对齐
if (arow = 0) then
with listgriddo
begin
canvas.Brush.color := clbtnface;
canvas.FillRect(Rect);
dx := 12;
//调整此值,控制字在网格中显示的水平位置
dy := 5;
//调整此值,控制字在网格中显示的垂直位置
canvas.TextOut(rect.left + dx, rect.top + dy, cells[acol, arow]);
end;
//使第一列出现CHECKBOX选框
if not (gdFixed in State) then
with TStringGrid(Sender).Canvasdo
begin
brush.Color:=clWindow;
FillRect(Rect);
if (listgrid.Cells[ACol,ARow]='yes') and (acol=0) then
Draw( (rect.right + rect.left - FCheck.width) div 2, (rect.bottom + rect.top - FCheck.height) div 2, FCheck );
if (listgrid.Cells[ACol,ARow]='no') and (acol=0) then
Draw( (rect.right + rect.left - FCheck.width) div 2, (rect.bottom + rect.top - FCheck.height) div 2, FNoCheck );
end;
//使颜色为原色
if ((acol<>0) and (arow<>0)) then
begin
listgrid.Canvas.FillRect(Rect);
listgrid.Canvas.font.color:=ClBlack;
listgrid.Canvas.TextOut(rect.Left+12,rect.top+5,listgrid.Cells[acol,arow])
end;

end;
 
用CXGRID吧,一切OK
 
自己画吧,在要放置CHECKBOX的列设置状态,当某状态时画未勾选状态,当某状态时画勾选状态
 
dbgrideh有。
 
advstringgrid1.AddCheckBox(0,advstringgrid1.row,false,true);
如何判断被选中?
 
后退
顶部