This is what works for me. Just drop a ComboBox on the same form as the StringGrid for each column you need a ComboBox for.
procedure TfrmMain.sgCellsClick(Sender: TObject);
var
nTop, nLeft, nWidth, nHeight : integer;
begin
if ( sgCells.Col = 0 ) then
begin
with cbCol0 do
begin
PositionCB( sgCells, nTop, nLeft, nHeight, nWidth );
Top := nTop;
Left := nLeft;
Width := nWidth;
Height := nHeight;
ItemIndex := Items.IndexOf( sgCells.Cells[ sgCells.Col, sgCells.Row ] );
Visible := True;
ActiveControl := cbCol0;
end;
end
else if ( sgCells.Col = 1 ) then
with cbCol1 do
begin
PositionCB( sgCells, nTop, nLeft, nHeight, nWidth );
Top := nTop;
Left := nLeft;
Width := nWidth;
Height := nHeight;
procedure TfrmMain.PositionCB( const sgGrid : TStringGrid; var iTop, iLeft, iHeight, iWidth : integer );
var
i, iStartRow, iStartCol : integer;
begin
with sgGrid do
begin
iStartRow := TopRow;
iStartCol := LeftCol;
iTop := Top;
iLeft := Left;
{ Compute Row Height }
for i := iStartRow to Row do
iTop := iTop + RowHeights[ i ] + GridLineWidth;
{ Compute Col Width }
for i := iStartCol to Col - 1 do
iLeft := iLeft + ColWidths[ i ] + GridLineWidth;
if ( FixedCols > 0 ) then
for i := 0 to FixedCols - 1 do
iLeft := iLeft + ColWidths[ i ] + GridLineWidth;
Thanks for that,
it doesn't quite work but it's better than I had.
Basically the activecontrol statement causes it to generate
"cannot focus a disabled or invisible widget"
so I took it out.
If I click on the scroll bar the highlighted cell is out of sync with the combobox position
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.