jmulans
Messages postés8Date d'inscriptionvendredi 10 juin 2005StatutMembreDernière intervention18 août 2007
-
25 juin 2007 à 15:01
dominique.stock
Messages postés436Date d'inscriptionvendredi 7 novembre 2003StatutMembreDernière intervention 8 octobre 2008
-
27 juin 2007 à 14:09
Bonjour
j'ai créé une Stringgrid, et j'utilise l'évènement onDrawCell pour changer les bordures sur certaines cellules.
mais le problème c'est que quand je clique sur une cellule, les bordures reviennent aux bordures par défaut
j'ai essayé en mettant GoDrawFocusSelected a true ou false ça ne change rien
dominique.stock
Messages postés436Date d'inscriptionvendredi 7 novembre 2003StatutMembreDernière intervention 8 octobre 20087 25 juin 2007 à 15:10
Bonjour,
Pourrais-tu nous donner l'événement OnDrawCell ?
Cela pourrais-être dû au fait qu'il faut que tu redessine la cellule pour tout les états du "State" (Sélectionné ou non)
Dom
cs_Loda
Messages postés814Date d'inscriptionvendredi 3 novembre 2000StatutMembreDernière intervention30 juillet 20093 25 juin 2007 à 15:11
salut,
si tu nous copiais ton code (OnDrawCell), on pourrait mieux comprendre d'où peut venir le problem.
Sinon, as-tu bien testé les flags et traité (selected, ...) ? Ajouter un "outputdebugstrin('Drawing')" dans ton event peut t'aider a comprednre quand il est appelé.
A+
Loda
Se poser les bonnes questions est le premier pas pour trouver les bonnes réponses.
jmulans
Messages postés8Date d'inscriptionvendredi 10 juin 2005StatutMembreDernière intervention18 août 2007 25 juin 2007 à 15:43
voila onDrawCell
j'ai enlevé tout ce qui n'avais aucun rapport, pour ne pas vous embrouiller
en fait c'est un planning, j'ai les personnes dans les cellules de gauche, et les jour en haut
je vous met un sreen avec :)
procedure TFenetrePrincipale.StringGrid_planningDrawCell(Sender: TObject;
ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
var
i,j: Integer;
Row1,Row2;
fusion: boolean;
begin
// fusion des cellules
// on recherche les cellules identiques a fusionner, puis on fusionne
Row1 := 1; Row2 := 1;
fusion := false;
if ACol = 0 then
for i:=1 to StringGrid_Planning.RowCount - 1 do
begin
if StringGrid_Planning.Cells[0,i] = StringGrid_Planning.Cells[0,i+1] then
begin
inc(Row2);
fusion := true;
end
else
begin
inc(Row1); inc(Row2);
fusion := false;
end;
if fusion = false then
begin
if (Row1 <> Row2) and (Row1 <> (Row2+1)) then
begin
MergedCells(StringGrid_Planning,ACol,ARow,0,Row1-1,0,Row2-1,State);
Row1 := Row2;
end else
begin
//StringGrid_Planning.Canvas.Pen.Color := clBlack;
//StringGrid_Planning.Canvas.Polyline([ point(rect.left, rect.bottom) , rect.BottomRight ]);
end;
end;
end;
end;
{*------------------------------------------------------------------------------
Fusionner des cellules
------------------------------------------------------------------------------*}
procedure MergedCells(AStringGrid:TStringGrid;CurrentCol,CurrentRow,Col1,Row1,Col2,Row2:Integer;CurrentState: TGridDrawState);
var x1,y1,x2,y2:Integer;
X,Y,i: Integer;
ARect:TRect;
begin
//Initialisations diverses
ARect:=Bounds(0,0,0,0);
x1:=Col1;
y1:=Row1;
x2:=Col2;
y2:=Row2;
//On vérifie que la zone fusionnée est valide
if x1<0 then x1:=0;
if x2>AStringGrid.ColCount-1 then x2:=AStringGrid.ColCount-1;
if y1<0 then y1:=0;
if y2>AStringGrid.RowCount-1 then x2:=AStringGrid.RowCount-1;
if (x1>x2) or (y1>y2) then
begin
Exit;
end;
for i:= Row1 to Row2-1 do
begin
ARect.Left:=AStringGrid.CellRect(1,i).Left;
ARect.Top:=AStringGrid.CellRect(1,i).Top;
ARect.Right:=AStringGrid.CellRect(AStringGrid.ColCount,i).Right;
ARect.bottom:=AStringGrid.CellRect(AStringGrid.ColCount,i).Bottom;
//Si la cellule courante est la dernière de la zone de fusion, on dessine dans la fusion le texte de la cellule en haut à gauche
if ((CurrentCol=Col2) and (CurrentRow=Row2)) then
begin
jmulans
Messages postés8Date d'inscriptionvendredi 10 juin 2005StatutMembreDernière intervention18 août 2007 26 juin 2007 à 10:18
oui j'ai essayé de mettre true ou false ça me donne la meme chose
en fait je ne fusionne que les cellules de gauche, ou il y a les personnes, le autres ne doivent pas l'etre, il ne doit juste pas y avoir de bordure entre elles
je dessine donc les bordures en blanc. mais quand je clique sur ces cellules ça me remet les birdures grises par defaut :-/
cs_Loda
Messages postés814Date d'inscriptionvendredi 3 novembre 2000StatutMembreDernière intervention30 juillet 20093 27 juin 2007 à 12:04
re,
@dominique.stock:
OutPutDebugString est un API de win pour le debug en release. Essai! Tu verra le message dans la fenetre "Event log". Indispensable pour debuger les events rapide ou qui ne peuvent pas être interomput (break point).
DefaultDrawing := false; +1
(sinon le focus vas te changer tes bordures. non?)
@jmulan:
hum.
d'abord, saches que l'event Draw est appelé un nombre très élevé de fois. Dons c'est important de bien l'optimiser et d'éviter tout "calculs". cad de calculer les états perso (tel que quelle cellules est fusionée avec quelles autres) en dehors de l'event.
J'ai fait un test. il ne marche pas bien, mais il peut peut-être t'aider.
unit TestGrid_frm;
SR: TGridRect;
begin
SG := sender as TStringGrid;
C := SG.Canvas;
//add test sur validite des index (cell doivent se toucher)
// Corrige le State. (cas le state vient d'UNE des deux cellules)
SR := sg.Selection;
if
(InRange(ACol1,SR.Left,sr.Right) and InRange(ARow1,SR.Top,SR.Bottom) ) or
(InRange(ACol2,SR.Left,sr.Right) and InRange(ARow2,SR.Top,SR.Bottom) ) then
State := State + [gdSelected];
// choisit les couleurs
if gdSelected in State then begin
C.Brush.Color := clBlue;
C.Pen.Color := clRed;
C.Pen.Width := 4;
C.Font.Color := clYellow;
end else begin
// add cas pour autre state
C.Brush.Color := clWhite;
C.Pen.Color := clRed;
C.Font.Color := clBlack;
end;
// add les zones
R.Top := Min(R1.Top,R2.Top);
R.Left := Min(R1.Left,R2.Left);
R.Bottom := Max(R1.Bottom,R2.Bottom);
R.Right := Max(R1.Right,R2.Right);
C.Rectangle(R);
// text of TopLeft cell:
C.TextRect(R,R.Left,R.Bottom, SG.Cells[Min(ACol1,ACol2),Min(ARow1,ARow2)]);
end;
procedure TfrmTestgrid.DrawCell_Normal(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
SG : TStringGrid;
C : TCanvas;
begin
SG := sender as TStringGrid;
C := SG.Canvas;
if gdSelected in State then begin
C.Brush.Color := clSkyBlue;
C.Pen.Width := 4;
C.Pen.Color := clYellow;
end else begin
// add cas pour autre state
C.Brush.Color := clYellow;
C.Pen.Color := clGray;
end;
procedure TfrmTestgrid.Init_Fusionnee;
var i,k : integer;
begin
for i := 0 to MAX_CELL_X do
for k := 0 to MAX_CELL_Y do
Fusionnee[i,k] := NO_CELL_POS;
// ajoute ici un chargement depuis un fichier ou autres.
// une "fusion" entre 2,2 et 2,3
Fusionnee[2,2].X := 3;
Fusionnee[2,2].Y := 2;
// ce system (simpliste) necessite une double reference.
Fusionnee[3,2].X := 2;
Fusionnee[3,2].Y := 2;
end;
procedure TfrmTestgrid.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
P : TodaCellPos;
begin
//test sur indice
if not InRange(ACol,0,MAX_CELL_X) then exit;
if not InRange(ARow,0,MAX_CELL_Y) then exit;
P := Fusionnee[ACol,ARow];
if (P.X -1) or (P.Y -1) then begin
// default drawing
DrawCell_Normal(Sender,ACol,ARow,Rect,State);
end else begin
OutPutDebugString('Draw : FUSION');
//Fusion
DrawCell_Fusionnee(Sender,ACol,ARow,P.X,P.Y, State);
end;
end;
procedure TfrmTestgrid.FormCreate(Sender: TObject);
begin
Init_Fusionnee;
end;
procedure TfrmTestgrid.StringGrid1SelectCell(Sender: TObject; ACol,
ARow: Integer; var CanSelect: Boolean);
var
P : TodaCellPos;
SG : TStringGrid;
myRect: TGridRect;
begin
SG := sender as TStringGrid;
//test sur indice
if not InRange(ACol,0,MAX_CELL_X) then exit;
if not InRange(ARow,0,MAX_CELL_Y) then exit;
P := Fusionnee[ACol,ARow];
if (P.X -1) or (P.Y -1) then begin
//no fusion
exit;
end else begin
//membre de fusion
// -> Select All the fusion
OutPutDebugString('Sel : FUSION');
end.
Bug du test:
- n'efface pas la second cellule du groupe lorsque le group pert le focus.
- la bordure doit être dessiner à la main à l'intérieur de la zone de la cellule.
Loda, de retour de son combat de trois jours avec l'administration (et tout ça pour payer mes impôts... grrr)
Se poser les bonnes questions est le premier pas pour trouver les bonnes réponses.