Page 1 of 1

DataGrid Scrollbar Issue

Posted: Sat Jun 01, 2013 5:07 pm
by nower
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?

Re: DataGrid Scrollbar Issue

Posted: Sat Jun 01, 2013 5:42 pm
by Klaus
Hi nower,

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


Best

Klaus

Re: DataGrid Scrollbar Issue

Posted: Sat Jun 01, 2013 5:59 pm
by nower
Yes!!!

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

Re: DataGrid Scrollbar Issue

Posted: Sat Jun 01, 2013 6:10 pm
by Klaus
Glad I could help :-)

Re: DataGrid Scrollbar Issue

Posted: Sun Jun 02, 2013 12:23 am
by nower
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.
:-)