Recent

Author Topic: StringGrid: Drag and Drop with Scroll Feature  (Read 1538 times)

DeBritto

  • Jr. Member
  • **
  • Posts: 68
StringGrid: Drag and Drop with Scroll Feature
« 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

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: StringGrid: Drag and Drop with Scroll Feature
« Reply #1 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.

DeBritto

  • Jr. Member
  • **
  • Posts: 68
Re: StringGrid: Drag and Drop with Scroll Feature
« Reply #2 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

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: StringGrid: Drag and Drop with Scroll Feature
« Reply #3 on: May 16, 2019, 07:58:03 am »
You may need to call StringGrid1.Invalidate to refresh the  stringgrid.

DeBritto

  • Jr. Member
  • **
  • Posts: 68
Re: StringGrid: Drag and Drop with Scroll Feature
« Reply #4 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?

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: StringGrid: Drag and Drop with Scroll Feature
« Reply #5 on: May 16, 2019, 03:01:07 pm »
Please provide us your latest demo source code.

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: StringGrid: Drag and Drop with Scroll Feature
« Reply #6 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..
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018