1、新建工程;
2、在Form1中放Table1,datasource1,dbgrid1;
3、设置数据库联接Table1.databasename='DBDEMOS',
tablename='custoly.db'
3、在dbgrid中加3个column,前面两个连数据,在OnDrawColumnCell事件写程序。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Forms,
Dialogs, DB, DBTables, Grids, DBGrids;
type
TForm1 = class(TForm)
DBGrid1: TDBGrid;
Table1: TTable;
DataSource1: TDataSource;
procedure DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if Column.FieldName='' then
begin
DBGrid1.Canvas.TextOut(rect.Left,rect.Top,'测试');
end;
end;
end.
行了