Page 1 of 2

Problem filling a DataGrid table

Posted: Thu Nov 25, 2010 4:25 pm
by exheusden
I have a main stack of data and want to make a substack which is an index to that data: each line of the datagrid table that makes up the single card of the substack is to point to a single card in the main stack (I already have this working, using "traditional" means, but I thought it would be a nice exercise to do it with a datagrid).

To fill the datagrid table, I use

Code: Select all

 open stack "Titles Grid"
   put titleList
   set the dgText of group "Titles" of stack "Titles Grid" to titleList
but this does not work— the table remains unaltered.

The put command is just a control, so that I could be certain that the variable titleList contains the correct data—it does.

Upon completion of the script, I tried the set command from the massage box, using some simple text instead of a variable—the set command works.

So why does the set command not work when in a script (the script is part of an on mouseUp button script in the main stack)?

Re: Problem filling a DataGrid table

Posted: Thu Nov 25, 2010 6:17 pm
by Klaus
Hi exheusden,

hmmm, looks like we can only guess...

Do you get any error dialog?
Does it work if the stack is already open?
Does it work if you also add the card descriptor: -> set the dgText of group "Titles" of cd "name or number of the card here" of stack "Titles Grid" ?


Best

Klaus

Re: Problem filling a DataGrid table

Posted: Thu Nov 25, 2010 6:20 pm
by bn
Hi Exheusden,

your script works for me although it does not specify the card in the substack. Seems that if there is only one card in the substack it still works. I definitely would add the card to your path.

So I dont know why it fails. Does it throw an error? Or does it fail silently? Maybe there is something wrong with your data which would not explain why you could set the data from the messages box.

Are you shure there is just one card with one datagrid group called "titles" in the substack?

Sorry, no big help from here.

regards

Bernd

Re: Problem filling a DataGrid table

Posted: Thu Nov 25, 2010 7:34 pm
by Zryip TheSlug
exheusden wrote:open stack "Titles Grid"
   put titleList
   set the dgText of group "Titles" of stack "Titles Grid" to titleList
Hi Exheusden,

You can use a try catch block to handle errors:

Code: Select all

try
  set the dgText of group "Titles" of stack "Titles Grid" to titleList
catch tTheError
  answer tTheError
end try
If I understand well that is only a sample of your code.
Did you lock messages before to set the dgText property? If yes, be sure to unlock messages before to set the dgText property:
http://lessons.runrev.com/spaces/lesson ... Suffering-


Regards,

Re: Problem filling a DataGrid table

Posted: Thu Nov 25, 2010 11:06 pm
by exheusden
Klaus:

There is no error dialogue;
It does not work if the stack is already open;
The result is the same when the card descriptor is included.


bn:

Indeed, it fails silently;
I can add the data either directly from the message box, or b cutting it and pasting it into the Contents panel, or by reading it from a file (I have written out the same data to a file to test this) directly into the Contents panel;
Yes, there is just one card.


Zryip TheSlug:

Your code results in a compilation error,
stack "Originals": compilation error at line 309 (Handler: not a command) near "catch", char 1

Re: Problem filling a DataGrid table

Posted: Thu Nov 25, 2010 11:47 pm
by bn
Hi Exheusden,

I just upload the simple stack that I made to test your code.
For whatever it is worth.

regards

Bernd

Re: Problem filling a DataGrid table

Posted: Fri Nov 26, 2010 12:33 am
by Klaus
exheusden wrote:...
Zryip TheSlug:
Your code results in a compilation error,
stack "Originals": compilation error at line 309 (Handler: not a command) near "catch", char 1
That is of course only a code snippet and should be used inside of your "mouseup" (or whatever) handler!

Code: Select all

on mouseup
  ...
  try
  set the dgText of group "Titles" of stack "Titles Grid" to titleList
   catch tTheError
   answer tTheError
  end try
...
end mouseup

Re: Problem filling a DataGrid table

Posted: Fri Nov 26, 2010 1:14 am
by Zryip TheSlug
Klaus wrote:That is of course only a code snippet and should be used inside of your "mouseup" (or whatever) handler!
Yes indeed! Thanks Klaus! ;)
exheusden wrote:I can add the data either directly from the message box, or b cutting it and pasting it into the Contents panel, or by reading it from a file (I have written out the same data to a file to test this) directly into the Contents panel;
Yes, there is just one card.
Exheusden,

Could you check the custom properties of the datagrid group, please?

For doing that:
1) By double clicking on the datagrid group with the pointer tool, open the inspector
2) In the inspector, go to the "Custom properties" tab
3) In the "set" popup menu, do you have a dgText property?


Regards,

Re: Problem filling a DataGrid table

Posted: Fri Nov 26, 2010 10:23 am
by exheusden
Klaus wrote: That is of course only a code snippet and should be used inside of your "mouseup" (or whatever) handler!
Of course, and that's just where I used it:

Code: Select all

on redoTest titleList
   open stack "Titles Grid"
   put "In redotest:" & return & titleList
   set the dgText of group "Titles" of stack "Titles Grid" to titleList
   set lockscreen to false
catch tTheError
     answer tTheError
   dispatch "ResetList" to group "Titles" of stack "Titles Grid"
end redoTest
Using LiveCode 4.5.1, if that helps.

Note that strange alignment of the catch line (just the same as in your code snippet).

The catch keyword appears in the Dictionary, but seems to have to belong to a try control structure. I shall have to find out how to implement such a structure.

Re: Problem filling a DataGrid table

Posted: Fri Nov 26, 2010 10:26 am
by exheusden
Zryip TheSlug wrote:Exheusden,

Could you check the custom properties of the datagrid group, please?

For doing that:
1) By double clicking on the datagrid group with the pointer tool, open the inspector
2) In the inspector, go to the "Custom properties" tab
3) In the "set" popup menu, do you have a dgText property?


Regards,
Wow! Indeed, the text is shown there correctly. This must indicate something, I just don't know what…

Re: Problem filling a DataGrid table

Posted: Fri Nov 26, 2010 10:45 am
by Zryip TheSlug
Hi Exheusden,
exheusden wrote:

Code: Select all

on redoTest titleList
   open stack "Titles Grid"
   put "In redotest:" & return & titleList
   set the dgText of group "Titles" of stack "Titles Grid" to titleList
   set lockscreen to false
catch tTheError
     answer tTheError
   dispatch "ResetList" to group "Titles" of stack "Titles Grid"
end redoTest
Should be:

Code: Select all

on redoTest titleList
   open stack "Titles Grid"
   put "In redotest:" & return & titleList
   try
      set the dgText of group "Titles" of stack "Titles Grid" to titleList
   catch tTheError
      answer tTheError
   end try
   set lockscreen to false
   dispatch "ResetList" to group "Titles" of stack "Titles Grid"
end redoTest
Regards,

Re: Problem filling a DataGrid table

Posted: Fri Nov 26, 2010 10:54 am
by Zryip TheSlug
exheusden wrote:
Zryip TheSlug wrote:Exheusden,

Could you check the custom properties of the datagrid group, please?

For doing that:
1) By double clicking on the datagrid group with the pointer tool, open the inspector
2) In the inspector, go to the "Custom properties" tab
3) In the "set" popup menu, do you have a dgText property?


Regards,
Wow! Indeed, the text is shown there correctly. This must indicate something, I just don't know what…

You should not have this property here. That is a clear indication that you have locked the messages before to fill the datagrid with the dgText property.

Do you have a line
set the lockmessages to true
or
lock messages

in the lines before the set dgText... line?

See my first reply for the lesson concerning this.


Regards,

Re: Problem filling a DataGrid table

Posted: Fri Nov 26, 2010 11:16 am
by exheusden
Zryip TheSlug wrote:You should not have this property here. That is a clear indication that you have locked the messages before to fill the datagrid with the dgText property.

Do you have a line
set the lockmessages to true
or
lock messages

in the lines before the set dgText... line?

See my first reply for the lesson concerning this.


Regards,

Brilliant! Many, many thanks. There is indeed a set lockmessages to true much earlier in the script that is not set off again. Setting it off solves the problem.

Now for the difficult part: can you explain why this is necessary, please?

Re: Problem filling a DataGrid table

Posted: Fri Nov 26, 2010 11:53 am
by Dixie
exhusden...

Page 137 of the 'User Guide'...

Be well

Dixie

Re: Problem filling a DataGrid table

Posted: Fri Nov 26, 2010 7:53 pm
by exheusden
Dixie wrote:exhusden...

Page 137 of the 'User Guide'...

Be well

Dixie
The comments on page 137 refer to sorting the data grid, not to filling it. I don't need to sort it, as the data is passed already sorted.