Solved

TStringGrid ans TComboBoxes

Posted on 2002-04-29
2
176 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
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Copy file in dll not working but working on exe ! 18 93
build html 5 client that connect to indy Tidtcpserver 3 395
Delphi cmd execution 6 60
Dev express lookupcombo 3 27
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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

770 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