请教AdvStringGrid1如何设置当前选中行某列的颜色

 我来答
就烦条0o
2016-07-19 · 知道合伙人软件行家
就烦条0o
知道合伙人软件行家
采纳数:33315 获赞数:46492
从事多年系统运维,喜欢编写各种小程序和脚本。

向TA提问 私信TA
展开全部
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, BaseGrid, AdvGrid;

type
TForm1 = class(TForm)
AdvStringGrid1: TAdvStringGrid;
procedure FormShow(Sender: TObject);
procedure AdvStringGrid1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure AdvStringGrid1Click(Sender: TObject);
private
{ Private declarations }
FCol, FRow :Integer;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormShow(Sender: TObject);
var
LCol, LRow :Integer;
begin
for LCol:=0 to 4 do
AdvStringGrid1.Cells[LCol, 0] := '第' + IntToStr(LCol+1) + '列';
for LRow :=1 to 9 do
begin
AdvStringGrid1.Cells[0, LRow] := '0' + IntToStr(LRow);
AdvStringGrid1.Cells[1, LRow] := '1' + IntToStr(LRow);
AdvStringGrid1.Cells[2, LRow] := '2' + IntToStr(LRow);
AdvStringGrid1.Cells[3, LRow] := '3' + IntToStr(LRow);
AdvStringGrid1.Cells[4, LRow] := '4' + IntToStr(LRow);
end;
end;

procedure TForm1.AdvStringGrid1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
AdvStringGrid1.MouseToCell(x, y, FCol, FRow);

end;

procedure TForm1.AdvStringGrid1Click(Sender: TObject);
var
i :Integer;
LColor :TColor;
begin
if (FRow>0) and (FRow<=AdvStringGrid1.RowCount-1) and AdvStringGrid1.RowSelect[FRow] then
begin
AdvStringGrid1.Colors[1, FRow] := clRed;
AdvStringGrid1.Colors[4, FRow] := clRed;
AdvStringGrid1.Repaint;
end;
LColor := AdvStringGrid1.Colors[0,1];
for i:=1 to AdvStringGrid1.RowCount - 1 do
begin
if i <> FRow then
begin
AdvStringGrid1.Colors[1, i] := LColor;
AdvStringGrid1.Colors[4, i] := LColor;
end;
end;
end;

end.
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
?>

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式