Delphi DBGrid高亮显示选中行源码
你的代码不变,添加红色部分代码即可。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, DBCtrls, Grids, DBGrids, DB, ADODB, Menus;
type
TCustomDBGridCracker = class(TCustomDBGrid);
TForm1 = class(TForm)
procedure Button1Click(Sender: TObject);
procedure DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure N1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
进入DBGrid events里双击DBGrid1DrawColumnCell,添加红色代码
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
with TCustomDBGridCracker(sender) do
begin
if DataLink.ActiveRecord = Row - 1 then // 如果被选中
begin
//Canvas.Brush.Color := clRed; //选中时颜色
//canvas.Font.Color := clyellow; //选中的字体颜色
canvas.Font.Style := [fsBold]; //选中时的字体
//canvas.Font.Size := 10;
end
else
begin
{if (DataSource.DataSet.RecNo mod 2)=0 then
canvas.brush.color:=clgreen else }
canvas.brush.color := clwindow;
canvas.Font.Style := [];
//canvas.Font.Size := 9;
//canvas.Font.Color := clblack;
end;
defaultdrawcolumncell(Rect, DataCol, Column, State);
end;
end;
end.
Delphi DBGrid高亮显示选中行源码
精选 转载![](https://ucenter.51cto.com/images/noavatar_middle.gif)
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
CListCtrl选中行
1、设置CListCtrl选中行m_list...
sed 控件 高亮显示 点击事件