DataGrid Scrollbar Issue

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
nower
Posts: 47
Joined: Wed May 22, 2013 11:02 pm

DataGrid Scrollbar Issue

Post by nower » Sat Jun 01, 2013 5:07 pm

I am building an app where I display a DataGrid with a list of items in a substack of the main stack.
Depending on the number of items in the list and the height of the stack I turn the vertical scrollbar in the DataGrid on or off.
When I turn the scrollbar on, it does not appear when I open the substack for the first time.
If I close the substack and reopen it, the scrollbar appears.

I have not been able to resolve the issue by myself despite a lot of attempts, so I am reaching out for help here.

More details:
In the main stack I build the list of items for the DataGrid and put them into a global array var. Then I call the substack (as modal, but I also tried modeless).
In the preOpenCard handler of the substack, I determine and set the size of the substack (based on the size of the main stack), and whether I need a scrollbar.
Depending on the result, I set the dgProps:

Code: Select all

 if tStackHeight > gStackHeight then
      put gStackHeight into tStackHeight
      set the dgProp["show vscrollbar"] of group "CategoryList" of me to true
      set the dgProp["scrollbar width"] of group "CategoryList" of me to 12
   else
      set the dgProp["show vscrollbar"] of group "CategoryList" of me to false
   end if
   set the height of this stack to tStackHeight
A bit later in the handler I position the DataGrid field on the stack, set the row height, and populate the grid with the data from the global array.

Code: Select all

   set the width of group "CategoryList" of me to tStackWidth
   set the height of group "CategoryList" of me to (tStackHeight - gMenuHeight - gButtonSize)
   set the left of group "CategoryList" of me to 0;
   set the top of group "CategoryList" of me to gButtonSize
   set the dgProp["row height"] of group "CategoryList" of me to gButtonSize
   
   # populate the data grid and hilite line
   set the dgData of group "CategoryList" to gDgData
   set the dgHilitedLines of group "CategoryList" to gDgHilitedLines
Everything works as expected, except the issue that the scrollbar doesn't appear during the first display of the substack, and it does appear when I close the substack and reopen it again.

Any idea what might cause this issue and how to resolve it?

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: DataGrid Scrollbar Issue

Post by Klaus » Sat Jun 01, 2013 5:42 pm

Hi nower,

does it work when you set the scrollbar AFTER populating the datagrid?


Best

Klaus

nower
Posts: 47
Joined: Wed May 22, 2013 11:02 pm

Re: DataGrid Scrollbar Issue

Post by nower » Sat Jun 01, 2013 5:59 pm

Yes!!!

Thank you so much, Klaus, this was driving me nuts!

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: DataGrid Scrollbar Issue

Post by Klaus » Sat Jun 01, 2013 6:10 pm

Glad I could help :-)

nower
Posts: 47
Joined: Wed May 22, 2013 11:02 pm

Re: DataGrid Scrollbar Issue

Post by nower » Sun Jun 02, 2013 12:23 am

It seems that the DataGrid is really picky about when you set which values.

The scrollbar worked fine after setting the data before switching the scrollbar on or off.
But setting the hilited line didn't work anymore, as I had it next to setting the grid data.

I got that working again by putting that statement back to where it previously was, after populating and positioning the datagrid.

My lesson from this:
- The datagrid is picky about the sequence in which you perform actions. If one sequence doesn't work, try another one.
- Set the data early.
- Set the hilite late.
:-)

Post Reply