| Цитата(superVad @ 2.12.2010, 12:34) | | Mach3, если тебе таблица не для работы с БД нужна то лучший вариант, что предложил Poseidon |
Если не для работы с БД, то обычного StringGrid достаточно. Необходимо только обрабатывать его событие onDrawCell, например так:
| Код | unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Grids, WinProcs;
type TForm1 = class(TForm) StringGrid1: TStringGrid; procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); end;
var Form1: TForm1;
implementation
{$R *.dfm}
function PointInGridRect(Col, Row: Longint; const Rect: TGridRect): Boolean; begin Result := (Col >= Rect.Left) and (Col <= Rect.Right) and (Row >= Rect.Top) and (Row <= Rect.Bottom); end;
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); var Format: Word; C: array[0..255] of Char; begin //------ нестандартная отрисовка ячеек
// задаем фон ячеек if (ACol<(Sender as TStringGrid).FixedCols)or((ARow<(Sender as TStringGrid).FixedRows)) then (Sender as TStringGrid).Canvas.Brush.Color:=TColor($F0F0F0)//фиксированные ячейки else if PointInGridRect(aCol, aRow, (Sender as TStringGrid).Selection) then (Sender as TStringGrid).Canvas.Brush.Color:=clYellow // выделение else // остальные if (arow mod 2)=0 then (Sender as TStringGrid).Canvas.Brush.Color:=clGray else (Sender as TStringGrid).Canvas.Brush.Color:=clWhite;
Format := DT_LEFT or DT_WORDBREAK; (Sender as TStringGrid).Canvas.FillRect(Rect); StrPCopy(C, (Sender as TStringGrid).Cells[ACol, ARow]); WinProcs.DrawText((Sender as TStringGrid).Canvas.Handle, C, StrLen(C), Rect, Format); end;
end.
|
Сорри за выбранные цвета ... |