Page 1 of 1

Maintaining indexes of Data Grid

Posted: Mon Sep 16, 2013 11:36 pm
by Jarren
Hi all,

I have a Data Grid in an iOS application, which can add new lines, delete any line, and sort lines. I understand that when a line is deleted, it actually removes the index of that line; so say I had 3 lines, and delete index 2, I still have index 1 and 3 even though they are now in lines 1 and 2. My problem is when I save the dgText of the Data Grid, and then reload them into the app upon launch, it resets the indexes of the data grid. Thus I now have index 1 and 2, instead of index 1 and 3. This is a problem because I have a seperate tab delimited data that refers to those indexes. And now the information is no longer synced up. Hopefully I explained that well enough, this is a question for a relative beginner, but will probably need an intermediate answer…

Thanks,
Jarren

Re: Maintaining indexes of Data Grid

Posted: Tue Sep 17, 2013 1:25 am
by Simon
Hi Jarren,
Since the index is important to you I wouldn't delete the index but put empty into it.
Maybe put numToChar(65293) into the dgLine?
That could mess up the way it looks for you.

I think though that one shouldn't depend on the indexes being constant, a sort could screw them up. Have you thought of using multidimensional arrays? That way you could set an id to each of your items.

Simon

Re: Maintaining indexes of Data Grid

Posted: Tue Sep 17, 2013 1:44 am
by Jarren
Thanks Simon, I think I figured out another way to do it. Basically adding another column and shoving the extra needed information inside does it. It's really thrilling to have found a simpler and more efficient way of doing something. :D

Re: Maintaining indexes of Data Grid

Posted: Tue Sep 17, 2013 1:48 am
by Simon
Great news Jarren!
Finding your own way of doing things is one of the cool aspects of liveCode. Later you may find that you can improve on it but for now it's working and that's what counts.

Simon