请教AdvStringGrid1如何设置当前选中行某列的颜色
1个回答
展开全部
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.
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.
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询