procedure TForm1.FormCreate(Sender: TObject); begin combobox1.visible := false; //初始化 end;
procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol,ARow: Integer; var CanSelect: Boolean); var R: TRect; org: TPoint; begin With Sender As TStringgrid Do If (ACol = 2) and (ARow >= FixedRows) Then //在第二列显示一个ComboBox Begin //取消选中模式 perform( WM_CANCELMODE, 0, 0 );
//确定ComboBox的位置 R := CellRect( Acol, Arow ); org:= Self.ScreenToClient( ClientToScreen( R.topleft )); With combobox1 do begin setbounds( org.X, org.Y, r.right-r.left, height ); itemindex := Items.IndexOf( Cells[ acol, arow ] ); Show; BringTofront;
procedure TForm1.ComboBox1Exit(Sender: TObject); //把在Combox选中的内容显示在StringGrid中 begin with sender as TCombobox do begin hide; if itemindex >= 0 then with stringgrid1 do cells[ col, row ] := items[itemindex]; end; End;