SG不連續多選 草稿

procedure TForm1.StringGrid1DrawCell(Sender: TObject. ACol, ARow: Integer. Rect: TRect. State: TGridDrawState).
begin
  with stringgrid1 do
  begin
  if cells[0,arow] = checked then
  begin
  canvas.brush.color := clhighlight;
  canvas.font.color := clhighlighttext;
  end
  else
  Canvas.Brush.Color := clWindow;
  Canvas.Font.Color := clWindowText;
  end
  Canvas.FillRect(Rect);
  TextRect(Rect, Rect.Left 2, Rect.Top 2, Cells[ACol, ARow]);
  end;
end;

procedure 1.StringGrid1SelectCell(Sender: TObject. ACol, ARow: Integer. var CanSelect: Boolean);
begin
with 1 do
begin if ARow = Row then Exit;
 if Cells[0, ARow] = Checked then
 Cells[0, ARow] := UnChecked
 else
 Cells[0, ARow] := Checked
 end;
end;  


如何在TStringGrid控件中按ctrl鍵選擇多行啊
推薦解答:
在MouseDown事件寫入以下代碼:
procedure TForm1.StringGrid1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if ssCtrl in Shift then
  StringGrid1.Options := [goFixedVertLine,goFixedHorzLine,goVertLine,goHorzLine,goRangeSelect,goRowSelect]
  else
    StringGrid1.Options := [goFixedVertLine,goFixedHorzLine,goVertLine,goHorzLine,goRowSelect] ;
end; 

 

 

delphi中StringGrid打開goRangeSelect可以多選,如何知道選擇了那些Cell?
procedure TForm1.Button1Click(Sender: TObject);
var
i,j:integer;
begin
for i:=Stringgrid1.Selection.left to Stringgrid1.Selection.Right do
begin
for j:=Stringgrid1.Selection.Top to Stringgrid1.Selection.Bottom do
Stringgrid1.cells[i,j]:='ok';
end;
end;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章