掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
StringGridで複数行選択するには? (ID:29635)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
[CTRL] で StringGrid1.Selection を累積していきそれを StringGrid1DrawCellで描画に反映させれば良いわけで こんな感じで CTRL で 複数エリア指定する事が可能になります SelectionRects : TList; implementation {$R *.dfm} //Grids.pas からコピー function PointInGridRect(Col, Row: Longint; const Rect: TGridRect): Boolean; begin Result := (Col >= Rect.Left) and (Col <= Rect.Right) and (Row >= Rect.Top) and (Row <= Rect.Bottom); end; procedure TForm2.SelectionClear; var I : Integer; begin for I:=0 to SelectionRects.Count -1 do begin Dispose(SelectionRects[I]); end; SelectionRects.Clear; end; procedure TForm2.FormCreate(Sender: TObject); begin SelectionRects := TList.Create; end; procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction); begin SelectionClear; SelectionRects.Free; end; procedure TForm2.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); var ARect : ^TGridRect; I : Integer; begin if gdSelected in State then begin StringGrid1.Canvas.Brush.Color := clRed; StringGrid1.Canvas.FillRect(Rect); end; for I:=0 to SelectionRects.Count-1 do begin ARect := SelectionRects[I]; if PointInGridRect(ACol,ARow,ARect^) = True then begin StringGrid1.Canvas.Brush.Color := clRed; StringGrid1.Canvas.FillRect(Rect); end; end; end; procedure TForm2.StringGrid1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin if (not (ssCTRL in SHIFT)) and (not (ssSHIFT in SHIFT)) then begin SelectionClear; StringGrid1.Invalidate; end; end; procedure TForm2.StringGrid1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var ARect : ^TGridRect; begin if (ssCTRL in SHIFT) or (ssSHIFT in SHIFT) then begin New(ARect); ARect^ := StringGrid1.Selection; SelectionRects.Add(ARect); StringGrid1.Invalidate; end else begin SelectionClear; New(ARect); ARect^ := StringGrid1.Selection; SelectionRects.Add(ARect); StringGrid1.Invalidate; end; end;
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2020 Takeshi Okamoto All Rights Reserved.