LiveCode LessonsLiveCode Data Grid Working With Data Grids (Forms & Tables)How Do I Refresh a Data Grid After Making Changes to a Template Through Script?

How Do I Refresh a Data Grid After Making Changes to a Template Through Script?

The command ResetList redraws a data grid after having copied in fresh copies of any templates. Here is an example of how you might use it.

## Get reference to group that serves as row template for data grid
put the dgProps["row template"] of group "DataGrid" into theRowTemplate

## For tables get reference to custom template for column
put the long id of group "My Column" of theRowTemplate into theColTemplate

## Make any updates to template
set the text of button 1 of theColTemplate to "New Option1" & cr & "New Option 2"

## Refresh the data grid
dispatch "ResetList" to group "DataGrid"


Chris Sheffield

I don't know if anyone still monitors this, but I'm having a bit of trouble with the above code. I'm trying to use it to resize a data grid when running an iOS app on the new iPad. My data grid ends up totally blank. I've verified that it is indeed populated with data. As far as I can tell all my code that handles the resizing is working correctly.

Any thoughts? Should I be doing something different to handle this sort of situation?

Trevor DeVore

Chris - All of your templates should receive the LayoutControl message when the data grid is resized. Can you provide some context as well as when you are making the call to ResetList? If you call ResetList during an event that targeted a control in the data grid then the engine will get upset when ResetList tries to delete the control.

Chris Sheffield

Basically all I'm trying to do is get a "retina" version of my data grid to display, and I'm really struggling for some reason. I've almost resorted to just creating two separate data grids. What I'm currently trying to get working is using two different templates, one for non-retina and one for retina. Maybe I've done this all wrong, but I've created a new card in the data grid template stack that contains my "retina" template. Everything is sized up to display properly. Then during preOpenCard, I'm swapping out the template as necessary like this:

set the dgProps["row template"] of group "data grid" to the long id of group "Row Template" of card 3 of stack "Data Grid Templates 1333731659203"

Then right after that I call ResetList using dispatch. I do some other positioning of the data grid based on the display resolution and after I set the data via dgText. But for some odd reason, I just can't see the data. I have no idea what I'm doing wrong. The data is there. I've checked the dgText property to make sure, but I can't see it. It's almost as if the data grid row height is too small. But I've tried setting that, and still am not seeing data. Any ideas? Like I said, I may end up resorting to just using two totally separate data grids.

Trevor DeVore

Have you checked to see if an error is being thrown using try catch or by handling errorDialog?

Chris Sheffield

I don't seem to be getting any errors, but maybe I'm not understanding where the try catch should be placed. I put it around

dispatch "ResetList" to group "data grid"

Is that correct? Or should I be "try"ing something else?

Thanks for the help.

Trevor DeVore

That is where I would think you would put them. It is always a good idea to be handling errors globally by adding errorDialog in a library stack. This way you know if any errors you haven't accounted for are being generated in a standalone. It may be that the error is somewhere else.

Does this code work fine in the IDE?

Add your comment

E-Mail me when someone replies to this comment