Ver la Versión Completa : encabezado en un grid
wil_ramone
11-11-2015, 17:48:40
Buenos días
como puedo poner el encabezado en forma horizontal en un grid?
es decir que no aparezca a si: ZONA
necesito que aparezca a si:
Z
O
N
A
espero me puedan ayudar gracias......
Casimiro Notevi
11-11-2015, 18:21:01
Primero vas a tener que aprender qué es horizontal y vertical ;)
wil_ramone
11-11-2015, 18:27:27
en forma vertical me confundí una disculpa
Casimiro Notevi
11-11-2015, 18:38:52
Prueba con: 'H'#13'O'#13'L'#13'A'
wil_ramone
11-11-2015, 18:51:40
esa fue mi primera opción y no funciono solo me agrego z|ona
Casimiro Notevi
11-11-2015, 18:59:28
¿Qué componente grid es?
wil_ramone
11-11-2015, 19:04:15
es un stringGrid
este es el código que uso para los títulos
_verRporte.stgReportes.Cells[0,0]:='ZONA';
_verRporte.stgReportes.Cells[1,0]:='SUP. ZONA';
_verRporte.stgReportes.Cells[2,0]:='No.';
_verRporte.stgReportes.Cells[3,0]:='SITIO';
_verRporte.stgReportes.Cells[4,0]:='SUCURSAL';
_verRporte.stgReportes.Cells[5,0]:='FECHA DE REGISTRO';
es el que necesito que cambie de orientación
y este es el que utilizo para darle color desde el evento OnDrawCell
if (ARow=0) and (ACol<=5) then begin
Canvas.Brush.Color := clBlack;
canvas.Font.Style:=[FsBold];
canvas.Font.Color:=clWhite;
Canvas.TextRect(Rect, Rect.Left + 3, Rect.Top + 2, cells[Acol, Arow]);
Canvas.FrameRect(Rect);
end;
Casimiro Notevi
11-11-2015, 19:07:16
Mira esto (http://www.clubdelphi.com/foros/showthread.php?t=58159).
Por cierto, recuerda poner los tags al código fuente, ejemplo:
http://www.clubdelphi.com/images/UtilizarTAGs.png
Gracias :)
ecfisa
11-11-2015, 20:59:17
Hola will_ramone.
Fijate si lo que estas buscando es algo como esto:
unit DBGridTitVert;
interface
uses Windows, Types, Graphics, Grids, DBGrids;
type
TDBGrid = class(DBGrids.TDBGrid)
private
FColsHeight : Integer;
procedure SetColsHeight(const Value: Integer);
protected
procedure DrawCell(ACol, ARow: Integer; ARect: TRect; State: TGridDrawState); override;
public
property ColsHeight: Integer read FColsHeight write SetColsHeight;
end;
implementation
{ TDBGrid }
procedure TDBGrid.DrawCell(ACol, ARow: Integer; ARect: TRect;
State: TGridDrawState);
var
LF : LOGFONT;
CurrentCol : TColumn;
FontName : string;
begin
if (ARow = FixedRows-1) and (ACol >= Integer(dgIndicator in Options)) then
begin
CurrentCol := Columns[ACol-1];
FontName := CurrentCol.Title.Font.Name;
ZeroMemory(@LF, SizeOf(LF));
LF.lfHeight := Canvas.Font.Height ;
LF.lfWidth := Canvas.Font.Size;
LF.lfEscapement := 10 * 90;
LF.lfCharSet := CurrentCol.Font.Charset;
Move(FontName, LF.lfFaceName, Length(FontName));
Canvas.Brush.Color := CurrentCol.Title.Color;
Canvas.Brush.Style := bsSolid;
Canvas.FillRect(ARect);
Canvas.Font.Handle:= CreateFontIndirect(LF);
Canvas.TextOut(ARect.Left + (ARect.Right - ARect.Left) div 2 - LF.lfWidth,
ARect.Bottom + LF.lfHeight, CurrentCol.Title.Caption);
end
else
inherited;
end;
procedure TDBGrid.SetColsHeight(const Value: Integer);
begin
if Value <> FColsHeight then
if Value > 30 then // (el alto que consideres razonable)
begin
FColsHeight := Value;
TStringGrid(self).DefaultRowHeight := Value;
end;
end;
end.
Uso del ejemplo:
unit Unit1;
interface
uses
Windows, ..., DBGrids, DBGridTitVert; // incluir último !!
...
procedure TForm1.FormCreate(Sender: TObject);
begin
DBGrid1.ColsHeight := 90;
end;
...
Muestra:
http://s14.postimg.org/po9rzaydd/will_ramone.png
Saludos :)
fjcg02
11-11-2015, 21:37:55
Ecfisa,
eres un puto maestro.
Saludos
ecfisa
11-11-2015, 21:47:43
Hayyyy ¡ A cuantos le diras lo mismo ! :D:D:D
Saludos :)
AgustinOrtu
11-11-2015, 23:33:07
No quiero ser aguafiestas, pero el amigo wil_ramone hablaba de un TStringGrid no de un TDBGrid :(
es un stringGrid
este es el código que uso para los títulos
_verRporte.stgReportes.Cells[0,0]:='ZONA';
_verRporte.stgReportes.Cells[1,0]:='SUP. ZONA';
_verRporte.stgReportes.Cells[2,0]:='No.';
_verRporte.stgReportes.Cells[3,0]:='SITIO';
_verRporte.stgReportes.Cells[4,0]:='SUCURSAL';
_verRporte.stgReportes.Cells[5,0]:='FECHA DE REGISTRO';
es el que necesito que cambie de orientación
y este es el que utilizo para darle color desde el evento OnDrawCell
if (ARow=0) and (ACol<=5) then begin
Canvas.Brush.Color := clBlack;
canvas.Font.Style:=[FsBold];
canvas.Font.Color:=clWhite;
Canvas.TextRect(Rect, Rect.Left + 3, Rect.Top + 2, cells[Acol, Arow]);
Canvas.FrameRect(Rect);
end;
ecfisa
12-11-2015, 00:44:55
Hola Agustín.
No quiero ser aguafiestas, pero el amigo wil_ramone hablaba de un TStringGrid no de un TDBGrid :(
Tenes razón ;), en ese caso:
unit SGTitVert;
interface
uses Windows, Types, Classes, Graphics, Grids;
type
TStringGrid = class(Grids.TStringGrid)
private
FTitleHeight : Integer;
procedure SetTitleHeight(const Value: Integer);
protected
procedure DrawCell(ACol, ARow: Integer; ARect: TRect; State: TGridDrawState); override;
public
property TitleHeight: Integer read FTitleHeight write SetTitleHeight default 30;
end;
implementation
procedure TStringGrid.DrawCell(ACol, ARow: Integer; ARect: TRect;
State: TGridDrawState);
var
LF : LOGFONT;
FontName : string;
begin
if ARow = FixedRows-1 then
begin
ZeroMemory(@LF, SizeOf(LF));
LF.lfHeight := Canvas.Font.Height ;
LF.lfWidth := Canvas.Font.Size;
LF.lfEscapement := 10 * 90;
LF.lfCharSet := DEFAULT_CHARSET;
FontName := Font.Name;
Move(FontName, LF.lfFaceName, Length(FontName));
Canvas.Brush.Color := FixedColor;
Canvas.Brush.Style := bsSolid;
Canvas.FillRect(ARect);
Canvas.Font.Handle:= CreateFontIndirect(LF);
Canvas.TextOut(ARect.Left + (ARect.Right - ARect.Left) div 2 - LF.lfWidth,
ARect.Bottom + LF.lfHeight, Cells[ACol,ARow]);
end
else
inherited;
end;
procedure TStringGrid.SetTitleHeight(const Value: Integer);
begin
if Value <> FTitleHeight then
if Value > 30 then
begin
FTitleHeight := Value;
RowHeights[FixedRows-1] := Value;
end;
end;
end.
Ejemplo de uso:
...
uses ..., SGTitVert; // incluir último !!
type
TForm1 = class(...
...
implementation
procedure TForm1.FormCreate(Sender: TObject);
var
sg: TStringGrid;
s : string;
c, r: Integer;
begin
sg := StringGrid1;
// los títulos de columna...
for c := 0 to sg.ColCount-1 do s := s + Format('Titulo%d,', [c+1]);
sg.Rows[sg.FixedRows-1].DelimitedText := s;
// cargar unos valores...
for r := sg.FixedRows to sg.RowCount-1 do
for c := 0 to sg.ColCount-1 do
sg.Cells[c,r] := Format('Celda %d',[r+c])
// alto de título
sg.TitleHeight := 90;
end;
...
Muestra:
http://s22.postimg.org/49fi22bep/will_ramone2.png
Saludos :)
fjcg02
12-11-2015, 17:49:28
Ecfisa,
eres el re-puto maestro. O el P.A. ( puto amo) ;)
Y no. últimamente no se lo digo a casi nadie...
Gracias
newtron
12-11-2015, 18:29:46
Ecfisa,
eres el re-puto maestro. O el P.A. ( puto amo) ;)
Totalmente de acuerdo. Yo hasta le estoy cogiendo manía. :p
vBulletin v3.6.8, Derechos ©2000-2024, Jelsoft Enterprises Ltd.