Lazarus

Programming => General => Topic started by: DeBritto on May 15, 2019, 11:27:03 pm

Title: StringGrid: Drag and Drop with Scroll Feature
Post by: DeBritto on May 15, 2019, 11:27:03 pm
Hi Folks,

I have a StringGrid with lots of cells. I can successfully drag and drop them. But there's a problem when I need to drop some cell that is localized beyond the screen area, i.e. when I need to scroll the screen to find the location to drop the cell. Is it possible to create a routine that scrolls the StringGrid to enable the user to find the position he wants?

Warm regards,
Christian
Title: Re: StringGrid: Drag and Drop with Scroll Feature
Post by: Handoko on May 16, 2019, 05:14:20 am
I haven't tried, but I think it will be easier to use TScrollBox or TListView or maybe write a new component.

But if you use TStringGrid, you can check the mouse position using TStringGrid.OnMouseMove event and if the mouse position reaches the edge of the stringgrid then you call TStringGrid.ScrollBy to scroll it by code.
Title: Re: StringGrid: Drag and Drop with Scroll Feature
Post by: DeBritto on May 16, 2019, 06:33:48 am
Thank you so much @Handoko,

The idea is awesome.
I have tried this:

Code: Pascal  [Select]
  1. procedure TFItemOrderer.StringGrid1MouseMove(Sender: TObject;
  2.   Shift: TShiftState; X, Y: Integer);
  3. var
  4.    pt : TPoint;
  5. begin
  6.    pt := Mouse.CursorPos;
  7.    pt := ScreenToClient(pt);
  8.    if pt.y > StringGrid1.ClientHeight then
  9.       StringGrid1.ScrollBy(0,-10);
  10. end;
  11.  

The StringGrid scrolls, but the screen gets messed.
Please, See gif attached
Title: Re: StringGrid: Drag and Drop with Scroll Feature
Post by: Handoko on May 16, 2019, 07:58:03 am
You may need to call StringGrid1.Invalidate to refresh the  stringgrid.
Title: Re: StringGrid: Drag and Drop with Scroll Feature
Post by: DeBritto on May 16, 2019, 02:01:32 pm
Hi,
I have tried and doesn't work, all the control is painted and return to the old position again.
Any ideas?
Title: Re: StringGrid: Drag and Drop with Scroll Feature
Post by: Handoko on May 16, 2019, 03:01:07 pm
Please provide us your latest demo source code.
Title: Re: StringGrid: Drag and Drop with Scroll Feature
Post by: jamie on May 16, 2019, 10:49:00 pm
Why not place a paper clip icon in the corner somewhere and tag that, it will remember the source..

go to the location of interest using normal means and then do a right click with a drown down menu etc..