Delphi32.com - Home!
| Home/News | Downloads | Forums | D32 Magazine | Resources | Info and Facts |  
 
 Custom InPlace Editor in StringGrid


How can I popup my own inplace editor (such as a combobox) in a string grid cell?   

    The following example demonstrates popping up a Combobox as an inplace editor to a Stringrid component.

    Example:
    procedure TForm .FormCreate(Sender: TObject);
    begin
     {The combobox height is not settable, so we will}
     {instead size the grid to fit the combobox!}
      StringGrid .DefaultRowHeight := ComboBox .Height;
     {Hide the combobox}
      ComboBox .Visible := False;
    end;
    procedure TForm .ComboBox Change(Sender: TObject);
    begin
     {Get the ComboBox selection and place in the grid}
      StringGrid .Cells[StringGrid .Col,
                        StringGrid .Row] :=
        ComboBox .Items[ComboBox .ItemIndex];
      ComboBox .Visible := False;
      StringGrid .SetFocus;
    end;
    procedure TForm .ComboBox Exit(Sender: TObject);
    begin
     {Get the ComboBox selection and place in the grid}
      StringGrid .Cells[StringGrid .Col,
                        StringGrid .Row] :=
        ComboBox .Items[ComboBox .ItemIndex];
      ComboBox .Visible := False;
      StringGrid .SetFocus;
    end;
    procedure TForm .StringGrid SelectCell(Sender: TObject; Col,
     Row: Integer;  var CanSelect: Boolean);
    var
      R: TRect;
    begin
      if ((Col = 3) AND
          (Row <> 0)) then begin
       {Size and position the combo box to fit the cell}
        R := StringGrid .CellRect(Col, Row);
        R.Left := R.Left + StringGrid .Left;
        R.Right := R.Right + StringGrid .Left;
        R.Top := R.Top + StringGrid .Top;
        R.Bottom := R.Bottom + StringGrid .Top;
        ComboBox .Left := R.Left +  ;
        ComboBox .Top := R.Top +  ;
        ComboBox .Width := (R.Right +  ) - R.Left;
        ComboBox .Height := (R.Bottom +  ) - R.Top;
       {Show the combobox}
        ComboBox .Visible := True;
        ComboBox .SetFocus;
      end;
      CanSelect := True;
    end;
    
    

     



  << Previous Faq     Complete List     Next Faq >>  



 
 Hits/month  2,500,000+ 
 Downloads
 (Since May 2000)
 7,393,709 
 Total Files  6,023 
 Forum msgs  7,670 
 Articles/FAQs  70+/900+ 
Kylix
Tips n Tricks
FAQs
Knowledge Base
Bug Listings
Articles
Books
Newsgroups
Links
Submissions
Testimonials
Advertising
Contact Us
About Us
Search Amazon:
Top Selling Software at Amazon

| Home/News | Downloads | Forums | Resources | Info and Facts | Testimonials |
  Site Search:
 


Comments/Problems: Webmaster@delphi32.com
Copyright © 1998-2006, Delphi32.com. All rights reserved.
Terms of Use