I would like to strike text of all cells from a line in a stringgrid by right click on that line. My code is about ok, but the clicked cell from the line is not striked (the other well)!?! Also, I have to click first on a line and then right click to proceed, I would like just to right click but don't know how :-/ My code:
procedure TForm1.StringGrid1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
i, j: integer;
begin
if Button = mbRight then
begin
j:=StringGrid1.Selection.Top;
If MessageDlg('Disable row '+IntToStr(j),
mtConfirmation, [mbYes, mbNo], 0, mbYes) =mrYes then
begin
With Stringgrid1 As TStringGrid Do
With Canvas Do
begin
for i := 0 to 2 do
begin
Rect := CellRect (i, StringGrid1.Selection.Top);
Font.Style := Font.Style + [fsStrikeOut];
FillRect(Rect);
DrawText(Canvas.Handle, PChar(Cells[i,j]), -1, Rect ,DT_CENTER );
end;
end;
end;
end;
end;
Wonderfull!!! But if I want to store the striked status I also add a column containing a 'x'; it works fine BUT when I create form I load the stringrid value and some 'x' in column 3, I try to use that code in form.create to strike these row but doesn't work :-(
for J := 1 to stringGrid1.RowCount-1 do
begin
if stringGrid1.Cells[3,J]='x' then
for I:=1 to 2 do
begin
StringGrid1.Canvas.Font.Style := Font.Style + [fsStrikeOut];
StringGrid1.Canvas.Brush.Color := clBtnFace; // title
StringGrid1.Canvas.FillRect(Rect);
Rect.Top := Rect.Top + 4;
drawText(Canvas.Handle, PChar(StringGrid1.Cells[I, J]), -1, Rect, DT_CENTER);
StringGrid1.Invalidate;
end
else
begin
StringGrid1.Canvas.Font.Style := Font.Style - [fsStrikeOut];
StringGrid1.Canvas.Brush.Color := clBtnFace; // title
StringGrid1.Canvas.FillRect(Rect);
Rect.Top := Rect.Top + 4;
drawText(Canvas.Handle, PChar(StringGrid1.Cells[I, J]), -1, Rect, DT_CENTER);
StringGrid1.Invalidate;
end;
end;
Any idea???
StringGrid1.Selection.TopwithStringGrid1.MouseCoord(X, Y).Y. There're two of them (of course you can use 'j' for the latter). - Sertac Akyuz