Subject | Re: [IBO] How do I turn off Selection in grid? |
---|---|
Author | Geoff Worboys |
Post date | 2000-12-18T22:12:16Z |
Michael,
repaints the grid selection as required. Alternatively you could just
attach code to the cell drawing handlers - which is what I used to do.
I've attached the code for my grid derivation below. To do what you
want, you only need the GetCellColor and GetCellProps overrides. In
those functions below you will see that I change the grid selection to
clInfoBk when the grid does not have focus, however you can just as
easily use clWindow or Self.Color to remove selection highlighting
altogether.
The code for DefaultDrawCell is simply there to ensure that checkmarks
are filled with clHighlightText color to make them more visible. Note
that this processing is far from efficient, but it does work.
HTH
Geoff Worboys
Telesis Computing
TIB_GridEnh = class(TIB_Grid)
public
procedure DefaultDrawCell( ACol, ARow: Longint;
ARect: TRect;
AState: TGridDrawState;
CellDisplayText: string;
CellAlignment: TAlignment ); override;
public
procedure GetCellColor( ACol, ARow: Longint;
AState: TGridDrawState;
var AColor: TColor ); override;
procedure GetCellProps( ACol, ARow: Longint;
AState: TGridDrawState;
var AColor: TColor;
const AFont: TFont ); override;
end;
procedure TIB_GridEnh.DefaultDrawCell( ACol, ARow: Longint;
ARect: TRect;
AState: TGridDrawState;
CellDisplayText: string;
CellAlignment: TAlignment );
var
AColumn: TIB_Column;
TxtCol: TColor;
i, j: integer;
begin
inherited;
AColumn := nil;
if DataLink.Prepared then
begin
if ( DataLink.ActiveRecord = DataRow[ ARow ] ) or
( DataLink.BufferRowCount = 0 ) then
AColumn := GridFields[ DataCol[ ACol ]]
else
begin
DataLink.BufferRecord := DataRow[ ARow ];
if DataLink.Dataset.BufferFields.RowState <> rsNone then
AColumn := BuffFields[ DataCol[ ACol ]];
end;
end;
if IndicateBooleans and
( ARow >= FixedRows ) and
Assigned( AColumn ) and AColumn.IsBoolean and
(gdSelected in AState) then begin
// Need to update the boolean glyph color so it can
// be seen when highlighted.
with Canvas do begin
TxtCol := TextColorFromColor(
Pixels[ARect.Left+1,ARect.Top+1] );
for i := ARect.Left to ARect.Right do begin
for j := ARect.Top to ARect.Bottom do begin
if Pixels[i,j] = clBlack then
Pixels[i,j] := TxtCol
else if Pixels[i,j] = clGray then
Pixels[i,j] := clBtnShadow
else if Pixels[i,j] = clSilver then
Pixels[i,j] := clBtnFace;
end;
end;
end;
end;
end;
procedure TIB_GridEnh.GetCellColor( ACol, ARow: Longint;
AState: TGridDrawState;
var AColor: TColor );
begin
inherited;
if gdSelected in AState then begin
if Focused then begin
AColor := clHighlight;
end else begin
AColor := clInfoBk;
end;
end;
end;
procedure TIB_GridEnh.GetCellProps( ACol, ARow: Longint;
AState: TGridDrawState;
var AColor: TColor;
const AFont: TFont );
begin
inherited;
if gdSelected in AState then begin
if Focused then begin
AColor := clHighlight;
AFont.Color := clHighlightText;
end else begin
AColor := clInfoBk;
AFont.Color := clInfoText;
end;
end;
end;
> But, I want to leave the dataset record selected justWhat I have done is created my own derivation of TIB_Grid which
> turn off the color in the grid. Also, your suggestion
> did not unselect the record.
repaints the grid selection as required. Alternatively you could just
attach code to the cell drawing handlers - which is what I used to do.
I've attached the code for my grid derivation below. To do what you
want, you only need the GetCellColor and GetCellProps overrides. In
those functions below you will see that I change the grid selection to
clInfoBk when the grid does not have focus, however you can just as
easily use clWindow or Self.Color to remove selection highlighting
altogether.
The code for DefaultDrawCell is simply there to ensure that checkmarks
are filled with clHighlightText color to make them more visible. Note
that this processing is far from efficient, but it does work.
HTH
Geoff Worboys
Telesis Computing
TIB_GridEnh = class(TIB_Grid)
public
procedure DefaultDrawCell( ACol, ARow: Longint;
ARect: TRect;
AState: TGridDrawState;
CellDisplayText: string;
CellAlignment: TAlignment ); override;
public
procedure GetCellColor( ACol, ARow: Longint;
AState: TGridDrawState;
var AColor: TColor ); override;
procedure GetCellProps( ACol, ARow: Longint;
AState: TGridDrawState;
var AColor: TColor;
const AFont: TFont ); override;
end;
procedure TIB_GridEnh.DefaultDrawCell( ACol, ARow: Longint;
ARect: TRect;
AState: TGridDrawState;
CellDisplayText: string;
CellAlignment: TAlignment );
var
AColumn: TIB_Column;
TxtCol: TColor;
i, j: integer;
begin
inherited;
AColumn := nil;
if DataLink.Prepared then
begin
if ( DataLink.ActiveRecord = DataRow[ ARow ] ) or
( DataLink.BufferRowCount = 0 ) then
AColumn := GridFields[ DataCol[ ACol ]]
else
begin
DataLink.BufferRecord := DataRow[ ARow ];
if DataLink.Dataset.BufferFields.RowState <> rsNone then
AColumn := BuffFields[ DataCol[ ACol ]];
end;
end;
if IndicateBooleans and
( ARow >= FixedRows ) and
Assigned( AColumn ) and AColumn.IsBoolean and
(gdSelected in AState) then begin
// Need to update the boolean glyph color so it can
// be seen when highlighted.
with Canvas do begin
TxtCol := TextColorFromColor(
Pixels[ARect.Left+1,ARect.Top+1] );
for i := ARect.Left to ARect.Right do begin
for j := ARect.Top to ARect.Bottom do begin
if Pixels[i,j] = clBlack then
Pixels[i,j] := TxtCol
else if Pixels[i,j] = clGray then
Pixels[i,j] := clBtnShadow
else if Pixels[i,j] = clSilver then
Pixels[i,j] := clBtnFace;
end;
end;
end;
end;
end;
procedure TIB_GridEnh.GetCellColor( ACol, ARow: Longint;
AState: TGridDrawState;
var AColor: TColor );
begin
inherited;
if gdSelected in AState then begin
if Focused then begin
AColor := clHighlight;
end else begin
AColor := clInfoBk;
end;
end;
end;
procedure TIB_GridEnh.GetCellProps( ACol, ARow: Longint;
AState: TGridDrawState;
var AColor: TColor;
const AFont: TFont );
begin
inherited;
if gdSelected in AState then begin
if Focused then begin
AColor := clHighlight;
AFont.Color := clHighlightText;
end else begin
AColor := clInfoBk;
AFont.Color := clInfoText;
end;
end;
end;