Datagrid- Smooth scrolling of long list

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
shoshinsha
Posts: 35
Joined: Fri Jul 18, 2014 5:17 am

Datagrid- Smooth scrolling of long list

Post by shoshinsha » Wed Mar 11, 2015 11:08 am

Hi All,
I have a datagrid with long list of data in a stack.
A scroller is created on opencard to enable scrolling of the datagrid, and then when one of the row is clicked (mouseUp), some actions will be taken (e.g. answer something).

Script on the card:

Code: Select all

on openCard
   send "scroller_create" to me in 0 sec
end openCard

on closeCard
   send "scroller_delete" to me in 0 sec
end closeCard

on scroller_create
   local tScrollerRect, tContentRect
   set the vScroll of grp "listA" to 0
   ##Only create a scroller on a mobile device
   if environment() is not "mobile" then exit scroller_create
   ##Set the area of the scroller
   put the rect of group "listA" into tScrollerRect
   ##Set the area of the content to be scrolled
   put 0,0,(the dgFormattedWidth of group "listA"),(the dgFormattedHeight of group "listA") into tContentRect
   ##Create the scroller control
   mobileControlCreate "scroller", "listScroll"
   put the result into sScrollerID
   ##Set the properties of the scroller
   mobileControlSet "listScroll", "rect",tScrollerRect
   mobileControlSet "listScroll", "contentRect",tContentRect
   mobileControlSet "listScroll", "visible",true
   mobileControlSet "listScroll", "scrollingEnabled",true
   mobileControlSet "listScroll", "vIndicator",true
   mobileControlSet "listScroll", "vscroll", 0
end scroller_create

on scroller_delete
   if environment() is not "mobile" then exit scroller_delete
   mobileControlDelete sScrollerID
end scroller_delete

on scrollerDidScroll hOffset, vOffset
   set the DGvScroll of group "listA" to vOffset
   set the DGSelectedLine of group "listA" to empty
end scrollerDidScroll

on mouseRelease
   set the dgHilitedLines of group "listA" to empty
end mouseRelease
Script in the datagrid behaviour:

Code: Select all

on mouseUp
   put the dgHilitedLines of group "listA" into theLine
   put the dgDataOfLine[theLine] of group "listA" into pData
   ##Some functions
   ....
end mouseUp
My problem is that as I pressed and scrolled the datagrid and released, it was often being detected as "mouseUp" (and actions were taken), even though I was just releasing my finger from scrolling.

I wonder if there is any control that I should take care of, so that as I am scrolling the datagrid it won't trigger mouseUp?

Thank you.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9680
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Datagrid- Smooth scrolling of long list

Post by dunbarx » Wed Mar 11, 2015 3:37 pm

Hi.

The scrollbars in a DG are named "scrollbar "dgHScrollbar" and scrollbar "dgScrollbar".

You could place an empty "mouseUp" handler in each of those scrollbars to trap and bury the message.

Craig Newman

shoshinsha
Posts: 35
Joined: Fri Jul 18, 2014 5:17 am

Re: Datagrid- Smooth scrolling of long list

Post by shoshinsha » Thu Mar 12, 2015 7:46 am

Thanks, Craig!
I've placed the handlers on each scrollbar "dgHScrollbar" and scrollbar "dgScrollbar", but still no luck ;(

Code: Select all

on mouseUp
   ##do nothing
end mouseUp

on mouseRelease
   ##do nothing
end mouseRelease

sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm
Location: Alexandria, Virginia

Re: Datagrid- Smooth scrolling of long list

Post by sritcp » Thu Mar 12, 2015 2:44 pm

Hi shoshinsha:

Try this in the data grid script:

Code: Select all

local sStartPosition
on mouseDown
put the vScroll of grp "listA" into sStartPosition
end mouseDown

on mouseUp
   if the vScroll of grp "listA" <> sStartPosition then exit mouseUp
   # followed by your usual code
   put the dgHilitedLines of group "listA" into theLine
   put the dgDataOfLine[theLine] of group "listA" into pData
   ##Some functions
   ....
end mouseUp
Regards,
Sri

shoshinsha
Posts: 35
Joined: Fri Jul 18, 2014 5:17 am

Re: Datagrid- Smooth scrolling of long list

Post by shoshinsha » Tue Mar 17, 2015 11:03 am

Hi Sri,

Thanks for the script! I've made some modification to make the scrolling+selection work:

Code: Select all

local sStartPosition

on mouseUp
   if the DGvScroll of grp "listA" <> sStartPosition then 
      set the dgHilitedLine of me to empty
      exit mouseUp
   end if
   put the dgHilitedLines of group "listA" into theLine
   ...
end mouseUp

on mouseRelease
   set the dgHilitedLine of me to empty
end mouseRelease

on mouseDown
   put the DGvScroll of grp "listA" into sStartPosition
   pass mouseDown
end mouseDown


Using vScroll on datagrid will return 0 value, so I changed it to DGvScroll. Also added "pass mouseDown", if not datagrid lines can't be "clicked".

Thanks a lot :D

sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm
Location: Alexandria, Virginia

Re: Datagrid- Smooth scrolling of long list

Post by sritcp » Tue Mar 17, 2015 2:51 pm

Also added "pass mouseDown", if not datagrid lines can't be "clicked".
I thought "mouseDown" goes to the datagrid components (field, row, ..) first before it went to the Datagrid itself (i.e., a message travels 'up' the object hierarchy). When you pass "mouseDown" in Datagrid script, it then goes to the card, I'd guess.

Regards,
Sri

MWCoastMedia
Posts: 32
Joined: Fri Jan 16, 2015 5:31 pm

Re: Datagrid- Smooth scrolling of long list

Post by MWCoastMedia » Wed May 25, 2016 3:07 pm

I had to modify the location of this slightly for use in LC8. Rather than placing the mouseUp/Down/Release scripts on the group, they need to be placed on the Row Behavior Script (accessed from the Property Inspector, my was labeled 'button "Behavior Script"' when using a form based datagrid).

When I had the code on the datagrid group script, I would get some errant datagrid item selections sometimes when scrolling. All seems good on Android and iOS now. :D

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”