Place a combobox in a string grid
The idea is to put an invisible combobox in the 3rd 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