Forum > General

what a mistake "tedit can not have tdbgrid as child"

<< < (2/3) > >>


--- Quote from: net_goose on March 30, 2010, 10:33:30 am ---FGrid.Parent:=Self; //------------------------The error occurs "tedit can not have tdbgrid as child"
--- End quote ---

Why would you want to place a TrxDBGrid component, which I assume is something visible, in a TEdit box?

This "new" component where Tedit - is, well for example, the text in this field is used to search data in DBGRID!

I am writing TEdit component with drop-down list the type DBGrid.
How would you explain the object DBGRID, serves as a list, and takes data from the database (when creating the object goes to the database and is displaying the necessary data to me), well, for example, a list of city streets.
In Delphi this window through the "setwindowpos" is being drawn under the object TEdit (
as a list similar to the drop-down list TDBComboBox, which is also where he is at the bottom of the form, he falls for the form fields).
I want to be displayed under DBGRID TEdit, the coordinates of which I
compute using ClientTotScreen.
But the problem is that if I write FGrid.parent: = self.Parent (as a form or container), then Lazarus makes Scrolling form (this was also observed in kylix3), suggesting that DBGRID is a component of the form, and it is therefore not should be, and should simply be a window with the data.
Moreover, if the coordinates are outside DBGRID form a window in Delphi is drawn in which the DBGRID me with the necessary data, which covers the form that is drawn on top of it, and even beyond, this is the reason for my part! Simple lists are composed not only of one field, and two, three, four.
I will try to show something like a screen shot.

Sorry for bad English :-[

Prompt please get in touch with developers Lazarus. :'(

Why don't you use a (customdrawn) combobox ?
What you need for the "popup" is a separate popup kind form/window.
Problem with a separate form/window is that the mainform looses focus. On windows I never got a real solution for this.

I will try to give you some tips, but I agree with Marc. I think that using custom drown combo box is more elegant solution.

This code creates separate form, puts the grid on it and shows it. When this GridForm is created, you should calculate the correct position on the screen where to show it.

Something like this, in your TOraEditShowGrid procedure:

--- Code: ---

if not Assigned(GridForm) then begin // just to be sure

  GridForm := TForm.Create(nil);

  GridForm.ShowInTaskBar := stNever;
  GridForm.BorderStyle := bsNone;
  GridForm.ClientHeight := FGrid.Height;
  GridForm.ClientWidth := FGrid.Width;

  FGrid.Parent := GridForm;
  FGrid.Align := alClient;

  GridClosing := False;
  GridForm.OnClose := @GridFormClose;
  GridForm.OnDeactivate := @GridFormDeactivate;

  H := GridForm.Height;
  W := GridForm.Width;

  P := ControlToScreen(Point(0, Self.Height)); // self is your TOraEdit

  R := Screen.MonitorFromWindow(Self.Handle).WorkareaRect;

  if P.y > R.Bottom - H then
    P.y := P.y - H - Self.Height;

  if P.y < R.Top then
    P.y := R.Top;

  if P.x > R.Right - W then
    P.x := R.Right - W;

  if P.x < R.Left then
    P.x := R.Left;

  GridForm.SetBounds(P.x, P.y, W, H);

--- End code ---

Of course, you must also define GridFormClose and GridFormDeactivate methods.
in GridFormClose, put:

--- Code: ---GridClosing := True;
CloseAction := caFree;
OraEdit.SetFocus; //do not forget to return focus to your edit control.
GridForm := nil;

--- End code ---

in GridFormDeactivate, put:

--- Code: ---if not GridClosing then GridForm.Close;

--- End code ---

And define variable GridClosing: Boolean;
I hope I didn't foget something important...


[0] Message Index

[#] Next page

[*] Previous page

Go to full version