Solved

TStringGrid ans TComboBoxes

Posted on 2002-04-29
2
179 Views
Last Modified: 2010-04-04
Hey!

Any hint on how I can put a combobox in a specific cell of a StringGrid ?

I know how to create at runtime a combobox which uses the StringGrid as parent but I want it to kind of use one specific cell as parent (when I scroll, for example, the combobox follows the cell)

Any help ?
0
Comment
Question by:qas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 1

Accepted Solution

by:
MBo earned 50 total points
ID: 6979295
Assume sg1- stringgrid
       cb1 - combobox (drop it in design time after stringgrid (to avoid bringtofront) and make visible=false;)

procedure TForm1.sg1SelectCell(Sender: TObject; ACol,
  ARow: Integer; var CanSelect: Boolean);
var
  R: TRect;
begin
  if ARow =1 then     begin
      R := SG1.CellRect(ACol, ARow);
      cb1.left := R.Left+ SG1.Left+1;
      cb1.top := R.Top + sg1.top+1;
      cb1.Width := sg1.ColWidths[acol];
      cb1.Tag:=ACol+65536*ARow;//remember cell
      cb1.Visible := True;
      cb1.SetFocus;
    end;
  CanSelect := True;
end;

procedure TForm1.cb1Change(Sender: TObject);
begin
SG1.Cells[cb1.Tag mod 65536,cb1.tag div 65536]:=
  cb1.Items[cb1.itemindex];
cb1.visible:=false;
end;

procedure TForm1.cb1Exit(Sender: TObject);
begin
cb1.visible:=false;
end;

procedure TForm1.sg1TopLeftChanged(Sender: TObject);
var
  R: TRect;
begin
      R := SG1.CellRect(cb1.Tag mod 65536,cb1.tag div 65536);
      cb1.left := R.Left+ SG1.Left+1;
end;
0
 
LVL 6

Expert Comment

by:zebada
ID: 6979354
Or if you want to have the combo box visible in the string grid all the time do this:

implementation

// Define the cell that you want the combo box in.
const
  cbCol=2;
  cbRow=3;

procedure TForm1.sgDrawCell(Sender: TObject; ACol, ARow: Integer; r: TRect; State: TGridDrawState);
begin
  with ( Sender as TStringGrid) do
  begin
      if ( (LeftCol<=cbCol) and (cbCol<LeftCol+VisibleColCount) and
           (TopRow<=cbRow) and (cbRow<TopRow+VisibleRowCount) ) then
      begin
        cb.Visible := true;
        if ( (ACol=cbCol) and (ARow=cbRow) ) then
          cb.SetBounds(Left+2+r.Left,Top+2+r.Top,r.Right+2-r.Left,r.Bottom+10-r.Top);
      end
      else
        cb.Visible := false;
  end;
end;

procedure TForm1.cbEnter(Sender: TObject);
var
  r: TGridRect;
begin
  r.Left := cbCol;
  r.Right := cbCol;
  r.Top := cbRow;
  r.Bottom := cbRow;
  sg.Selection := r;
end;

procedure TForm1.cbExit(Sender: TObject);
begin
  sg.SetFocus;
end;

procedure TForm1.sgSelectCell(Sender: TObject; ACol, ARow: Integer; var CanSelect: Boolean);
begin
  if ( (ACol=cbCol) and (ARow=cbRow) ) then
    cb.SetFocus;
end;
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses
Course of the Month11 days, 16 hours left to enroll

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question