mouse tekerlek hareketiyle data üzerinde hareket edebiliyor.
aktif satırın rengi belirlenebiliyor.
vb bazı özellikleri var.. sizlerle paylaşmak istedim..
Kod: Tümünü seç
unit SrDBGrid;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, Grids, DBGrids,
graphics, forms, dbtables, db;
type
TSrDBGrid = class(TDBGrid)
private
FLines : integer;
FGetGridFocus : boolean;
Fcoloralter : Tcolor;
FcolorSelect : Tcolor;
FcolorselText : Tcolor;
function GetGridFocus: boolean;
procedure alcoloralter (const Value: Tcolor);
procedure alcolorselect (const Value: Tcolor);
procedure alcolorseltext(const Value: Tcolor);
protected
function DoMouseWheelDown(Shift: TShiftState; MousePos: TPoint):
Boolean; override;
function DoMouseWheelUp(Shift: TShiftState; MousePos: TPoint):
Boolean; override;
procedure DrawColumnCell(const Rect: TRect; DataCol: Integer;
Column: TColumn; State: TGridDrawState); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property ColorAlternative : Tcolor read Fcoloralter write alcoloralter;
property ColorSelect : Tcolor read FcolorSelect write alcolorselect;
property ColorSelectText : Tcolor read FcolorselText write alcolorseltext;
property MoveByRows : integer read FLines write FLines;
property OnMouseWheelDown;
property OnMouseWheelUp;
end;
procedure Register;
implementation
///**************************************************************************///
constructor TSrDBGrid.Create(AOwner: TComponent);
begin
FLines:=1;
inherited;
color :=$00F7DFD6;
coloralternative:=$00F9EAE3;
colorselect :=clwhite;
colorselecttext :=clred;
end;
///**************************************************************************///
destructor TSrDBGrid.Destroy;
begin
inherited;
end;
///**************************************************************************///
function TSrDBGrid.GetGridFocus: Boolean;
begin
Result := True;
if FGetGridFocus and CanFocus and (not (csDesigning in ComponentState)) then
begin
if not Self.Focused then Self.SetFocus;
Result := Focused;
end;
end;
///**************************************************************************///
function TSrDBGrid.DoMouseWheelDown(Shift:TShiftState;MousePos:TPoint):Boolean;
begin
Result := False;
if Assigned(OnMouseWheelDown) then OnMouseWheelDown(Self,Shift,MousePos,Result);
if not Result then
begin
if not GetGridFocus then Exit;
if DataLink.Active then Result := DataLink.DataSet.MoveBy(FLines) <> 0;
end;
end;
///**************************************************************************///
function TSrDBGrid.DoMouseWheelUp(Shift: TShiftState; MousePos: TPoint):Boolean;
begin
Result := False;
if Assigned(OnMouseWheelUp) then OnMouseWheelUp(Self, Shift,MousePos, Result);
if not Result then
begin
if not GetGridFocus then Exit;
if DataLink.Active then Result := DataLink.DataSet.MoveBy(-FLines) <> 0;
end;
end;
///**************************************************************************///
procedure Register;
begin
RegisterComponents('FSH', [TSrDBGrid]);
end;
///**************************************************************************///
procedure TSrDBGrid.DrawColumnCell(const Rect: TRect; DataCol: Integer;
Column: TColumn; State: TGridDrawState);
begin
inherited;
if datalink.DataSet.RecNo mod 2 =0 then Canvas.Brush.Color:= coloralternative;
If (gdSelected in state) then
begin
canvas.Brush.Color := colorselect;
canvas.Font.Color:=colorselecttext;
end;
DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
///**************************************************************************///
procedure TSrDBGrid.alcoloralter(const Value: Tcolor);
begin
if Fcoloralter <> Value then
begin
Fcoloralter := Value;
RecreateWnd;
end;
end;
///**************************************************************************///
procedure TSrDBGrid.alcolorselect(const Value: Tcolor);
begin
if fcolorselect <> value then
begin
FcolorSelect := Value;
RecreateWnd;
end;
end;
///**************************************************************************///
procedure TSrDBGrid.alcolorseltext(const Value: Tcolor);
begin
if fcolorseltext <> value then
begin
FcolorselText := Value;
RecreateWnd;
end;
end;
///**************************************************************************///
end.