Somehow, I think I should be using DrawGrid rather than StringGrid but I am
not sure how.
I need to create a ComboBox on my grid when certain cells are selected.
Right now I get the rect's of the cell selected and if appropriate I display
the ComboBox over the cell and add the selected item to the grid cell. This
works pretty good, but does not look real professional especially when the
scrolls are used. The grid moves but the ComboBox stays put.
Is there an easy way to create a ComboBox as the StringGrid (DrawGrid) cell?
The ComboBox must be dynamic. only present if cell is selected and other
conditions are met.
Thank you in advance for your support.
--
Mike Sandoval
procedure TForm1.ProjGridSelectCell(Sender: TObject; ACol,
ARow: Integer; var CanSelect: Boolean);
var
crect: TRect;
begin
if (ACol = 2) then
begin
crect := ProjGrid.CellRect(ACol, ARow);
GridCombo.Top := ProjGrid.Top + crect.Top + 2;
GridCombo.Left := ProjGrid.Left + crect.Left + 2;
GridCombo.Width := crect.Right - crect.Left;
GridCombo.ItemIndex := GridCombo.Items.IndexOf(ProjGrid.Cells[ACol,
ARow]);
GridCombo.Visible := True;
end
else
GridCombo.Visible := False;
end;
procedure TForm1.GridComboExit(Sender: TObject);
begin
GridCombo.Visible := False;
end;
procedure TForm1.GridComboChange(Sender: TObject);
begin
ProjGrid.Cells[ProjGrid.Selection.Left,ProjGrid.Selection.Top] :=
GridCombo.Text;
end;
procedure TForm1.ProjGridTopLeftChanged(Sender: TObject);
begin
GridCombo.Visible := False;
end;
That helped. It looks much nicer now.
Regards,
Mike
TDrawgrid has the same problem.
> I need to create a ComboBox on my grid when certain cells are selected.
> Right now I get the rect's of the cell selected and if appropriate I display
> the ComboBox over the cell and add the selected item to the grid cell. This
> works pretty good, but does not look real professional especially when the
> scrolls are used. The grid moves but the ComboBox stays put.
This problem can be solved by setting the comboboxes Parent to the stringgrid.
But it will not work properly in this scenario unless you modify the parent
grid a bit as well. The Delphi grid controls have not been designed to serve
as parents for other controls other then the inplace editor, and so they do
not echo WM_COMMAND messages from child controls back to the control as
CN_COMMAND. That is easily fixed, fortunately.
unit ControlStringgrid;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids;
type
TControlStringgrid = class(TStringgrid)
private
{ Private declarations }
Procedure WMCommand( var msg: TWMCommand ); message WM_COMMAND;
protected
{ Protected declarations }
public
{ Public declarations }
published
{ Published declarations }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('PBGoodies', [TControlStringgrid]);
end;
{ TControlStringgrid }
procedure TControlStringgrid.WMCommand(var msg: TWMCommand);
begin
If EditorMode and Assigned( Inplaceeditor )
and ( msg.Ctl = InplaceEditor.Handle )
Then
inherited
Else
If msg.Ctl <> 0 Then
msg.result :=
SendMessage( msg.ctl, CN_COMMAND,
TMessage(msg).wparam,
TMessage(msg).lparam );
end;
end.
--
Peter Below (TeamB)
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be