Link to home
Start Free TrialLog in
Avatar of delbrad
delbrad

asked on

Floating a control over a dbgrid

I am kind of stuck with the following:
I am currently floating a control (datepicker  from rxlib) over a grid with the following code:

procedure TLog.LogGridDrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
    If DataCol = 0 then begin
      If LogModule.tblLog.State in [dsEdit, dsInsert] then begin
        If (gdFocused in State) then begin
         Date.Left := LogGrid.Left + Rect.Left;
         Date.Top := LogGrid.Top + Rect.Top;
         Date.Width := Rect.Right - Rect.Left;
         Date.Visible := True;
        end;
       end;
      end;
   end;

And  when I want to make the control invisible again I use the following code:

procedure TLog.LogGridColExit(Sender: TObject);
begin
  If LogGrid.Columns[0].Title.Caption = Date.Name then
 Date.Visible := False;
end;

Ok now to my question:

How do I make the control invisible when I click on the horizontal scroll bar and also when I click on a component outside of the grid.


P.S.   If you try the code above you will see it only makes the control invisible when I click on another field in the grid.

Thanks in advance for any help you can provide.

Note to Igor

If it would not take up much of your time then I think coming up with a
away to override the dbgrid would be the  best bet. And since this sound like a big task I have increased the points as you can see.

 
Avatar of inter
inter
Flag of Türkiye image

Dear delbrad,
I can not find an easy way to your problem. Especially for scrolling, we have to oportunities. Either, create a new componenent from TDBGrid which also includes datepicker and handle WMVScroll and WMHScroll messages or in run-time, tell windows to send scroll commands to one of your methods. Or we may try to find a DBGrid component in which we can receive scrolling messages.

Which one do you prefer, If you want to override the component I try to help but it may took few hours(or an hour if no bugs, etc) or we may try to capture the scroll event.
Please notify!
Igor
Avatar of delbrad
delbrad

ASKER

Edited text of question
Avatar of delbrad

ASKER

Adjusted points to 150
With joy I try to override it, however, in my time zone it is 24:25 now. So, if I can handle, I ask you to send you email. But if any one have a more briliant idea, I will see on tomorrow.
Note : I plan to combine DBGrid and datepicker so that you can set the column of it an it works as you want OK?
Thanks,
Igor
Hi delbrad
Notify me when you there, I am fixing up few things. It will be yours in a while.
Igor,(sleepless old guru)
I should leave, now. Since I do not have an internet connection at home, I can not send you the component.
Sorry,
Sincerely,
Igor
Well I have your solution--this procedure is from a program I'm currently writting that uses the technique:

procedure TfrmJournalPosting.dbgTransactionsDrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumn;
  State: TGridDrawState);
var
   Point     : TPoint;
   OutputStr : String;
begin
     Point.X := 1;
     Point.Y := 1;

//THESE LINES ARE THE ONES THAT WORK--AS YOU CAN SEE THERE IS
//A COLUMN RESIZING PROBLEM THAT IT FIXES TOO--WORKS WHEN YOU
//MAKE IT WIDER, BUT NOT WHEN YOU MAKE IT NARROWER :-)
     If (Sender as TDBGrid).ControlAtPos(Point, True) <>
        TControl((Sender as TDBGrid).Columns.Items[0]) then
        dlcAccountNum.Visible := False; //Fixes scrolling problem
     If Column.Field.FieldName = dlcAccountNum.DataField then
        dlcAccountNum.Width := Column.Width + 1; //Fixes column resizing problem
     If ((gdFocused in State) or (gdSelected in State)) and
        (Column.Field.FieldName = dlcAccountNum.DataField) and
        (Screen.ActiveControl = dbgTransactions) then
     begin
          dlcAccountNum.Left := Rect.Left + (Sender as TDBGrid).Left + 1;
          dlcAccountNum.Top := Rect.Top + (Sender as TDBGrid).Top + 1;
          dlcAccountNum.Visible := True;
     end
end;

To make it invisible when you exit, just define the following procedure for the OnExit event of the grid:

procedure TfrmJournalPosting.dbgTransactionsExit(Sender: TObject);
begin
     if Screen.ActiveControl <> dlcAccountNum then
        dlcAccountNum.Visible := False;
end;

There is a BIG problem with this however.  If you click on the column that uses the DateTimePicker and it is selected but the "floater" is not active (has been set invisible) the grid will pick it up and enter edit mode.  My suggestion to you is to just forget about doing it yourself and buying a product like InfoPower or SofTouch to do what you want.  Here are their sites:

www.woll2woll.com
www.softouchdev.com

If you have problems, I can give you all of the code dealing with the floating--just write me if you need it all or not.  What I gave you should work as is as long as you change all the references to your components and cut out what references things specific to my program.

Good Luck,
Scott

Hi delbrad,

I am back again, the component is about 200 lines of code. Do you want me to send it as a comment or e-mail it to you.

I am waiting for your request
Igor
Avatar of delbrad

ASKER

To Igor
From delbrad
 
If you can, could you email it directly to me at

delbrad@brigadoon.com

P.S. Thank you for all your help!
ASKER CERTIFIED SOLUTION
Avatar of inter
inter
Flag of Türkiye image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Why the rejection?  Did you even try it?  An explanation of why you rejected would be nice so that I can improve the answer to your expectations.  

Scott
Avatar of delbrad

ASKER

To Igor

Currently the component is working, will advise if I find a bug


Thank you again.
One actually feels good when he wants to find the answer to a previous question and pays 15 point only just to find the answer is in some e-mail. Isn't it?!
My friend, we are always here to serve, writedown a 0 point question, I would deal(note that this question is dated back to Jan 1998, delphi components change much (at least10 million new was created by this time) so, this solution may not be what you want in after 2 and a half year later, anyway

igor (inter)
I have posted a question, igor, and I will bevery thankful for your help..