我想通过右键单击该行来触发stringgrid中一行中所有单元格的文本.我的代码是关于ok的,但是来自该行的单击单元格没有被攻击(另一个很好)!?!此外,我必须首先点击一行,然后右键单击继续,我想只是右键单击但不知道如何: - /我的代码:
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;
完美的事情!但是,如果我想存储受到攻击的状态,我还会添加一个包含'x'的列; 它工作正常但是 当我创建表单时我加载了stringrid值和第3列中的一些'x',我尝试在form.create中使用该代码来敲击这些行但是不起作用:-(
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;
任何的想法???