先在StringGrid1录入一次,然后在StringGrid2录入第二次,如果StringGrid2.Cells[StringGrid2.Col,StringGrid2.Row] 不等于 StringGrid1.Cells[StringGrid2.Col,StringGrid2.Row]
让StringGrid2.Cells[StringGrid2.Col,StringGrid2.Row]的单元格文字显示红色 procedure TDataimportForm.StringGrid2KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
beginif
StringGrid2.Cells[StringGrid2.Col,StringGrid2.Row] <> StringGrid1.Cells[StringGrid2.Col,StringGrid2.Row] then
begin
messagebeep(0);
让StringGrid2.Cells[StringGrid2.Col,StringGrid2.Row]单元格文字显示红色
end;怎样实现
让StringGrid2.Cells[StringGrid2.Col,StringGrid2.Row]的单元格文字显示红色 procedure TDataimportForm.StringGrid2KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
beginif
StringGrid2.Cells[StringGrid2.Col,StringGrid2.Row] <> StringGrid1.Cells[StringGrid2.Col,StringGrid2.Row] then
begin
messagebeep(0);
让StringGrid2.Cells[StringGrid2.Col,StringGrid2.Row]单元格文字显示红色
end;怎样实现
Rect: TRect; State: TGridDrawState);
自绘
advstringgrid里好像有validate处理事件,能更方便些
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids;type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
StringGrid2: TStringGrid;
procedure StringGrid2DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
private
{ Private declarations }
procedure SetGridColor(ARow,ACol: Integer;Rect: TRect;StrGrid,StrGrid2: TStringGrid);
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.SetGridColor(ARow,ACol: Integer;Rect: TRect;StrGrid,StrGrid2: TStringGrid);
var
strValue: String;
begin
with StrGrid do
begin
//画背景
if (ARow > 0) and (ACol > 0) then
begin
if StrGrid.Cells[ACol,ARow]<>StrGrid2.Cells[ACol,ARow] then
Canvas.Font.Color := clRed
else
Canvas.Font.Color := clBlack;
Canvas.FillRect(Rect);
end;
//计算显示在矩形框中的左上角位置
strValue := Cells[ACol,ARow];
//在矩形框中写值
Canvas.TextRect(Rect,Rect.Left+5,Rect.Top+(Rect.Bottom-Rect.Top-Canvas.TextHeight(strValue)) div 2,strValue);
end;
end;procedure TForm1.StringGrid2DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
SetGridColor(ARow,ACol,Rect,StringGrid2,StringGrid1);
end;end.