unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Grids, StdCtrls, Contnrs, ExtCtrls, BarPanel, StringGridUnit, RectPointUnit; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; BarPanel1: TBarPanel; StringGrid1: TStringGrid; Button3: TButton; Button4: TButton; procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); procedure Button2Click(Sender: TObject); procedure BarPanel1HorzScroll(Sender: TObject); procedure BarPanel1VertScroll(Sender: TObject); procedure BarPanel1Resize(Sender: TObject); procedure StringGrid1TopLeftChanged(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button4Click(Sender: TObject); private FComboBoxList: TObjectList; FButtonList: TObjectList; procedure UpdateGridControlPosition; public { Public 宣言 } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); begin FComboBoxList := TObjectList.Create; FButtonList := TObjectList.Create; StringGrid1.Options := StringGrid1.Options + [goThumbTracking]; StringGrid1.ScrollBars := ssNone; StringGrid1.Align := alClient; UpdateGridControlPosition; end; procedure TForm1.FormDestroy(Sender: TObject); begin FButtonList.Free; FComboBoxList.Free; end; procedure TForm1.Button1Click(Sender: TObject); var I: Integer; c: TComboBox; b: TButton; begin FComboBoxList.Clear; FButtonList.Clear; for I := StringGrid1.FixedRows to StringGrid1.RowCount - 1 do begin c := TComboBox.Create(StringGrid1); c.Parent := StringGrid1; // c.BoundsRect := StringGrid1.CellRect(1, I); c.Items.Text := IntToStr(I); FComboBoxList.Add(c); b := TButton.Create(StringGrid1); b.Parent := StringGrid1; b.Caption := IntToStr(I); FButtonList.Add(b); end; UpdateGridControlPosition; end; procedure TForm1.BarPanel1HorzScroll(Sender: TObject); begin StringGrid1.LeftCol := BarPanel1.HorzScrollBar.Position; end; procedure TForm1.BarPanel1VertScroll(Sender: TObject); begin StringGrid1.TopRow := BarPanel1.VertScrollBar.Position; end; const ComboColumn: Integer = 2; const ButtonColumn: Integer = 3; procedure TForm1.UpdateGridControlPosition; var I: Integer; c: TComboBox; b: TButton; r: TRect; begin BarPanel1.HorzScrollBar.Min := StringGrid1.FixedCols; BarPanel1.HorzScrollBar.Max := (StringGrid1.ColCount-1); BarPanel1.HorzScrollBar.PageSize := GridVisibleNormalColCount(StringGrid1); BarPanel1.HorzScrollBar.Position := StringGrid1.LeftCol; //Fix Normal //0 1 2 3 4 5 6 7 // ^^^^^^ BarPanel1.VertScrollBar.Min := StringGrid1.FixedRows; BarPanel1.VertScrollBar.Max := (StringGrid1.RowCount-1); BarPanel1.VertScrollBar.PageSize := GridVisibleNormalRowCount(StringGrid1); BarPanel1.VertScrollBar.Position := StringGrid1.TopRow; //コントロールがない場合は処理しない if not (FComboBoxList.Count = (StringGrid1.RowCount - StringGrid1.FixedRows)) then Exit; Assert(FComboBoxList.Count = (StringGrid1.RowCount - StringGrid1.FixedRows), 'UpdateComboPosition実行時エラー'); for I := StringGrid1.FixedRows to StringGrid1.RowCount - 1 do begin c := TComboBox(FComboBoxList.Items[I-StringGrid1.FixedRows]); if GridCellVisible(StringGrid1, ComboColumn, I) then begin c.Visible := True; r := StringGrid1.CellRect(ComboColumn, I); SetRectWidth(r, StringGrid1.ColWidths[ComboColumn]); SetRectHeight(r, StringGrid1.RowHeights[I]); c.BoundsRect := r; end else begin c.Visible := False; end; b := TButton(FButtonList.Items[I-StringGrid1.FixedRows]); if GridCellVisible(StringGrid1, ButtonColumn, I) then begin b.Visible := True; r := StringGrid1.CellRect(ButtonColumn, I); SetRectWidth(r, StringGrid1.ColWidths[ButtonColumn]); SetRectHeight(r, StringGrid1.RowHeights[I]); b.BoundsRect := r; end else begin b.Visible := False; end; end; end; procedure TForm1.Button2Click(Sender: TObject); var I: Integer; J: Integer; begin for I := 0 to StringGrid1.RowCount - 1 do for J := 0 to StringGrid1.ColCount - 1 do StringGrid1.Cells[J, I] := BoolToStr(GridCellVisible(StringGrid1, J, I, gcvoInBottomRight), True); end; procedure TForm1.Button4Click(Sender: TObject); var I: Integer; J: Integer; begin for I := 0 to StringGrid1.RowCount - 1 do for J := 0 to StringGrid1.ColCount - 1 do StringGrid1.Cells[J, I] := BoolToStr(GridCellVisible(StringGrid1, J, I), True); end; procedure TForm1.Button3Click(Sender: TObject); begin StringGrid1.FixedCols := 0; end; procedure TForm1.BarPanel1Resize(Sender: TObject); begin UpdateGridControlPosition; end; procedure TForm1.StringGrid1TopLeftChanged(Sender: TObject); begin UpdateGridControlPosition; StringGrid1.Refresh; end; end.