掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
stringgridでセルを比較して一致しなかったら色を付けるには? (ID:39253)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
ほれ TInplaceEdit = class(Grids.TInplaceEdit); TComparisonStyle = (csNone,csENTER,csREAL); TStringGrid = class(Grids.TStringGrid) private FSaveRow: Integer; FSaveCol: Integer; FComparisonColor: TColor; FComparison: TComparisonStyle; FComparisonCol1: Integer; FComparisonCol2: Integer; procedure SetComparisonColor(Value: TColor); procedure SetComparison(Value: TComparisonStyle); procedure SetComparisonCol1(Value: Integer); procedure SetComparisonCol2(Value: Integer); protected procedure DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState); override; function GetEditText(ACol, ARow: Longint): string; override; procedure SetEditText(ACol, ARow: Longint; const Value: string); override; procedure KeyPress(var Key: Char); override; public constructor Create(AOwner: TComponent); override; published property Comparison: TComparisonStyle read FComparison write SetComparison; property ComparisonColor: TColor read FComparisonColor write SetComparisonColor; property ComparisonCol1: Integer read FComparisonCol1 write SetComparisonCol1; property ComparisonCol2: Integer read FComparisonCol2 write SetComparisonCol2; end; //--------------------------------------- procedure TStringGrid.SetComparisonColor(Value: TColor); begin FComparisonColor := Value; Invalidate; end; procedure TStringGrid.SetComparison(Value: TComparisonStyle); begin FComparison := Value; Invalidate; end; procedure TStringGrid.SetComparisonCol1(Value: Integer); begin FComparisonCol1 := Value; Invalidate; end; procedure TStringGrid.SetComparisonCol2(Value: Integer); begin FComparisonCol2 := Value; Invalidate; end; procedure TStringGrid.KeyPress(var Key: Char); var C: TColor; begin if (Key = #13) and (FComparison = csENTER) then begin if (FSaveCol <> -1) and (FSaveRow <> -1) then begin C := Color; if Cells[FComparisonCol1, FSaveRow] <> Cells[FComparisonCol2, FSaveRow] then begin C := FComparisonColor; end; TInplaceEdit(InplaceEditor).Color := C; InvalidateRow(FSaveRow); end; end; inherited KeyPress(Key); end; procedure TStringGrid.SetEditText(ACol, ARow: Longint; const Value: string); var C: TColor; begin inherited; if (FComparison = csREAL) then begin C := Color; if Cells[FComparisonCol1, ARow] <> Cells[FComparisonCol2, ARow] then begin C := FComparisonColor; end; TInplaceEdit(InplaceEditor).Color := C; InvalidateRow(FSaveRow); end; end; function TStringGrid.GetEditText(ACol, ARow: Longint): string; var C: TColor; begin Result := inherited GetEditText(ACol,ARow); if (FComparison <> csNONE) then begin FSaveCol := ACol; FSaveRow := ARow; C := Color; if Cells[FComparisonCol1, ARow] <> Cells[FComparisonCol2, ARow] then begin C := FComparisonColor; end; TInplaceEdit(InplaceEditor).Color := C; end; end; procedure TStringGrid.DrawCell(ACol, ARow: Longint; ARect: TRect;AState: TGridDrawState); begin if (FComparison <> csNONE) then begin if gdFixed in AState then begin inherited DrawCell(ACol, ARow, ARect, AState); end else begin Canvas.Brush.Color := Color; if Cells[FComparisonCol1, ARow] <> Cells[FComparisonCol2, ARow] then begin Canvas.Brush.Color := FComparisonColor; end; end; end; inherited DrawCell(ACol, ARow, ARect, AState); end; constructor TStringGrid.Create(AOwner: TComponent); begin inherited; FSaveCol := -1; FSaveRow := -1; FComparison := csREAL; FComparisonCol1 := 1; FComparisonCol2 := 2; FComparisonColor := clRed; end;
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.