掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
DBGridの背景色に一行置きに色をつけるには? (ID:28695)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
編集中の背景の色も変更に対応版です unit DBGridEx; interface uses Windows,SysUtils, Classes, Messages, Graphics, Controls, Grids, DBGrids; type TMouseDown2Event = procedure(Sender:TObject;Row,Col:Integer) of Object; TDBGridEx = class(TDBGrid) private FSaveRow : Integer; FSaveCol : Integer; FMouseDown2Event : TMouseDown2Event; public procedure DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState);override; procedure WMLButtonDown(var Message: TWMLButtonDown); message WM_LBUTTONDOWN; published property SaveRow : Integer read FSaveRow; property SaveCol : Integer read FSaveCol; property InplaceEditor; property Row; property Col; property OnMouseDown2 : TMouseDown2Event read FMouseDown2Event write FMouseDown2Event; end; procedure Register; implementation procedure TDBGridEx.DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState); begin FSaveRow := ARow; FSaveCol := ACol; inherited; end; procedure TDBGridEx.WMLButtonDown(var Message: TWMLButtonDown); begin inherited; if Assigned(InplaceEditor) = True then begin if Assigned(FMouseDown2Event) = True then OnMouseDown2(Self,Row,Col); end; Exit; end; procedure Register; begin RegisterComponents('Component', [TDBGridEx]); end; end. --------------------------------------------------------- 使用方法は //1行ごとに背景色を変える procedure TForm3.DBGridEx1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); begin if DBGridEx1.SaveRow mod 2 = 0 then begin DBGridEx1.Canvas.Brush.Color := clRed; end else begin DBGridEx1.Canvas.Brush.Color := clBlue; end; DBGridEx1.DefaultDrawColumnCell(Rect,DataCol,Column,State); end; //編集中の背景の色も変える procedure TForm3.DBGridEx1MouseDown2(Sender: TObject; Row, Col: Integer); begin if Row mod 2 = 0 then begin DBGridEx1.InplaceEditor.Brush.Color := clRed; end else begin DBGridEx1.InplaceEditor.Brush.Color := clBlue; end; end; BDS2006 + XP
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.