• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 250
  • Last Modified:

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.

 
0
delbrad
Asked:
delbrad
  • 7
  • 4
  • 2
  • +1
1 Solution
 
interCommented:
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
0
 
delbradAuthor Commented:
Edited text of question
0
 
delbradAuthor Commented:
Adjusted points to 150
0
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

 
interCommented:
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
0
 
interCommented:
Hi delbrad
Notify me when you there, I am fixing up few things. It will be yours in a while.
Igor,(sleepless old guru)
0
 
interCommented:
I should leave, now. Since I do not have an internet connection at home, I can not send you the component.
Sorry,
Sincerely,
Igor
0
 
millerwCommented:
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

0
 
interCommented:
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
0
 
delbradAuthor Commented:
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!
0
 
interCommented:
Got, it?
Please, try it with and send bug report!(Then I'll fix them and you go on your program)

Sincerely,
Igor
0
 
millerwCommented:
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
0
 
delbradAuthor Commented:
To Igor

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


Thank you again.
0
 
karouriCommented:
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?!
0
 
interCommented:
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)
0
 
karouriCommented:
I have posted a question, igor, and I will bevery thankful for your help..
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

  • 7
  • 4
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now