syloux
asked on
StringGrid and combobox
Is it possible to put a combobox on a cell on a StringGrid ? I'm using Delphi 5, and I want the user to select data from a combobox on cell 1, and type data for other cells.
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Are the items of the comobox stored in a Table?
Yes, it is possible.
I had code for that somewhere...hmmmm....
I had code for that somewhere...hmmmm....
Yes, it is possible.
I had code for that somewhere...hmmmm....
I had code for that somewhere...hmmmm....
You can create one dynamically at run time.
In this example you start with a blank form, drop a stringgrid on the form and a button (to close the app).
Click on a cell of the stringgrid and a combobox will be created inside the string grid.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Grids;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
Button1: TButton;
ComboBox1: TComboBox;
procedure Button1Click(Sender: TObject);
procedure StringGrid1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender : TObject);
begin
Close;
end;
procedure TForm1.StringGrid1Click(Se nder: TObject);
var
TempComboBox : TComboBox;
begin
TempComboBox := TComboBox.Create(self);
TempComboBox.Parent := StringGrid1;
TempComboBox.Width := 100;
TempComboBox.Height := 50;
TempComboBox.Top := 1;
TempComboBox.Left := 1;
TempComboBox.Items.Add('On e');
TempComboBox.Items.Add('Tw o');
TempComboBox.Items.Add('Th ree');
TempComboBox.Visible := true;
// TempComboBox.Free;
end;
end.
In this example you start with a blank form, drop a stringgrid on the form and a button (to close the app).
Click on a cell of the stringgrid and a combobox will be created inside the string grid.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Grids;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
Button1: TButton;
ComboBox1: TComboBox;
procedure Button1Click(Sender: TObject);
procedure StringGrid1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender
begin
Close;
end;
procedure TForm1.StringGrid1Click(Se
var
TempComboBox : TComboBox;
begin
TempComboBox := TComboBox.Create(self);
TempComboBox.Parent := StringGrid1;
TempComboBox.Width := 100;
TempComboBox.Height := 50;
TempComboBox.Top := 1;
TempComboBox.Left := 1;
TempComboBox.Items.Add('On
TempComboBox.Items.Add('Tw
TempComboBox.Items.Add('Th
TempComboBox.Visible := true;
// TempComboBox.Free;
end;
end.
I would go with Drareq's example...much better than my quick-n-dirty solution.
I had code for that somewhere...hmmmm....