if fdmTable.Locate('ID', aID, []) then Result := fdmTable.FieldByName(aFieldName).AsString else Result := EmptyStr;
finally if (fdmTable.Active) then fdmTable.Close;
fdmTable.Free; end; end;
begin DBGrid := Sender as TDBGridEh;
with DBGrid do begin Canvas.FillRect(Rect); DefaultDrawColumnCell(Rect, DataCol, Column, State);
if NOT(DataSource.DataSet.Bof and DataSource.DataSet.Eof) then begin if (gdFocused in State) or (gdSelected in State) then begin if (DataSource.DataSet.State = dsBrowse) then begin Canvas.Brush.Color := clGreen; // Color of the selected row Canvas.Font.Color := clWhite; end else if (DataSource.DataSet.State in [dsEdit, dsInsert]) then begin Canvas.Brush.Color := clWhite; // Color of the row been edited or inserted Canvas.Font.Color := clNavy; end;
end;
if (Column.HideDuplicates) and NOT((gdFocused in State) or (gdSelected in State)) then begin ID := DataSource.DataSet.FieldByName('ID').AsInteger; PriorID := Pred(ID);
{Only the first cell of the column with duplicate value has the color clMoneyGreen.} if (PriorCellValue = CurrentCellValue) then Canvas.Brush.Color := clWhite // Color of the other cells of the column with the same duplicate value as the first one. else Canvas.Brush.Color := clMoneyGreen; // Color of the first cell with the duplicate value end; end;
select id,name,ROW_NUMBER() OVER(PARTITION BY name ORDER BY name) as xx from name值相同的会产生相同的xx值,从1开始排序增加,程序里就好处理了。
procedure DBGridEh1GetCellParams(Sender: TObject; Column: TColumnEh; AFont: TFont; var Background: TColor; State: TGridDrawState); begin if cds.FieldValues['xx'] = 1 then AFont.Color := clRed; if cds.FieldValues['xx'] = 2 then AFont.Color := clgreed;