Controls in a Grid Enviroment

I would like to place a TCombobox in a TCustomGrid enviroment. As you fill out the data in the grid, the user can use these controls. As you add a row a new control is available to be filled in.
kehansenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

intheCommented:
here a example using stringgrid:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Grids;

type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    ComboBox1: TComboBox;
    procedure FormCreate(Sender: TObject);
    procedure ComboBox1Change(Sender: TObject);
    procedure ComboBox1Exit(Sender: TObject);
    procedure StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer; var CanSelect: Boolean);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
 {The combobox height is not settable, so we will}
 {instead size the grid to fit the combobox!}
  StringGrid1.DefaultRowHeight := ComboBox1.Height; {Hide the combobox}
  ComboBox1.Visible := False;
end;

procedure TForm1.ComboBox1Change(Sender: TObject);
begin
 {Get the ComboBox selection and place in the grid}
  StringGrid1.Cells[StringGrid1.Col,StringGrid1.Row] :=
ComboBox1.Items[ComboBox1.ItemIndex];
  ComboBox1.Visible := False;
  StringGrid1.SetFocus;
end;

procedure TForm1.ComboBox1Exit(Sender: TObject);
begin
 {Get the ComboBox selection and place in the grid}
  StringGrid1.Cells[StringGrid1.Col,StringGrid1.Row] :=
    ComboBox1.Items[ComboBox1.ItemIndex];
  ComboBox1.Visible := False;
  StringGrid1.SetFocus;
end;

procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol,ARow: Integer;  var CanSelect: Boolean);
var
  R: TRect;
begin
// if ((ACol = 1) AND
  //    (ARow <> 0)) then begin
   {Size and position the combo box to fit the cell}
    R := StringGrid1.CellRect(ACol, ARow);
    R.Left := R.Left + StringGrid1.Left;
    R.Right := R.Right + StringGrid1.Left;
    R.Top := R.Top + StringGrid1.Top;
    R.Bottom := R.Bottom + StringGrid1.Top;
    ComboBox1.Left := R.Left + 1;
    ComboBox1.Top := R.Top + 1;
    ComboBox1.Width := (R.Right + 1) - R.Left;
    ComboBox1.Height := (R.Bottom + 1) - R.Top;   {Show the combobox}
    ComboBox1.Visible := True;
    ComboBox1.SetFocus;
    CanSelect := True;
  end;
//end;

end.

maybe helps
Regards Barry
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kehansenAuthor Commented:
Thanks for your input.  I could make this work but with multiple rows and controls on the fly it would be cumbersome.  I was looking for a more elegent solution. I seem to remember something about hanging a control on a pointer to the cell.  
0
rwilson032697Commented:
You could take a look a TAdvStringGrid (downloadable from here: http://www.tmssoftware.com/).

Cheers,

Raymond.
0
kehansenAuthor Commented:
Thanks for your suggestion, but I actually have a custom component I need to use.  I knew if someone could get it to work with a TCombobox.  I could get it to work with mine.
0
kehansenAuthor Commented:
My expectation were a little higher.  I was hoping I would find someone who had done this before and would have lots of code.  This will work. Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.