Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I put a control in a cell of a grid 2

Status
Not open for further replies.

Bogdan81

Programmer
Oct 2, 2002
11
RO
I wanna put a combobox inside a cell of a TStringgrid and I don't now how ! Can you help me ?
 
You can acquire a number of StringGrid like components that will give you combo boxes (and other facilities). Some of these cost money and others are free.

A fairly simple one, which is free and comes with source code, is TImpStringGrid by Magnus Lidman. I found it on Torry's Delphi Pages.

Andrew
 
Place a combobox in a string grid

The idea is to put an invisible combobox in the 3[sup]rd[/sup] column in the StringGrid, and when needed make it visible
The following event handlers are needed

1) onCreate (Form)
2) onChange = OnExit (ComboBox)
3) onSelectCell (StringGrid)



procedure TForm1.FormCreate(Sender: TObject);
begin
//adjust heigth of combobox with line height of stringgrid
StringGrid1.DefaultRowHeight := ComboBox1.Height;
ComboBox1.Visible := False;
end;

procedure TForm1.ComboBox1Change(Sender: TObject);
begin
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 = 3) and (ARow <> 0)) then
begin
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;
ComboBox1.Visible := true;
ComboBox1.SetFocus;
end;
CanSelect := True;
end;

Regards Steven van Els
SAvanEls@cq-link.sr
 
I brought a component named TAdvStringGrid which can include combox box, button, Ellipse..., hyperlink, hint for each cell and many many more features.

For more info, refer to
 
Thx Svanel ! Good code, but there is a small problem. If you are intrested please tell me !




 
FamWS, hi.

I use TMSSoftware's Grid Pack and it's brilliant, well worth the money. For little things like sorting columns when you click the header - they're a god send.

lou

 
What is the problem?

Regards Steven van Els
SAvanEls@cq-link.sr
 
The problem occurs at last cell. If the cell isn't displayed fully and you press and hold the mouse button on the arrow of the combobox the cells are scrolled until the last one is displyed and a combobox appears after last cell. Don't know why ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top