Strange DataGrid behavior

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Strange DataGrid behavior

Post by lohill » Sun Dec 20, 2009 12:49 am

I am experiencing a very strange behavior while trying to begin working with dataGrids. I have a substack that starts out with one card on which I have placed and grouped onto a single background: 2 dataGrids, 1 regular field and three buttons. Two of the buttons are simple Previous and Next. The first DataGrid I filled by hand by pasting tab delimited data into the Contents field of the Inspector. It looks fine. The second DataGrid is intended to be a summary for the information in the first grid - sums etc.

The first thing I tried to do was to get the two grids to scroll together so that scrolling one would automatically scroll the other. It is the horizontal scrolling that I want to work together. Having done something similar with table fields before I tried (to no avail) I tried scripts like the one below:

Code: Select all

on scrollbarDrag
   put the hscroll of me into tScroll
   set the hscroll of field "Sums" to tscroll
end scrollbarDrag
After a little experimentation with things like hscroll of group "Sums" and other things I thought might work, I ended up loosing all the data that had previously been in my main Grid. I again put my data into the grid with an manual paste. I did not want to keep doing this by hand so I created a third button suggested in one of the DataGrid tutorials for automatically loading the data into a grid. It looks like this:

Code: Select all

on mouseUp
   answer file "Select the .TXT file to load:"
   put it into theFile
   put true into firstLineHeaders
   set the dgText[firstLineHeaders] of group "PortfolioGrid" to URL("file:" & theFile)
end mouseUp
With this button now grouped with the rest I made a new card which had all the objects on it. The new card was created with no data (no surprise) and no headings (a bit of a surprise). With my trusty load button I decided to fill in the data in card 2. The data loaded but card 2 ended up having just data and no headings. I went back to card 1 and it had headings but no data. I was able to repeat this a number of times by fortunately quitting REV without saving changes and then coming back up with card one only.
Something seems to be going on but it makes no sense to me. Is it possibly related to the fact that the data I am trying to load into card 2 is exactly the same as the data I already have in card 1? I did discover among my attempts that the one of the heading fields had an extra space after it and consequently that column did not load but by fixing that, everything except headings loaded.
As you can see I have not gone very far into this and I will have way more to do.. I still want to control scrolling from one Grid and I want to get sums from the large grid to put into the Sums grid. I have been looking at the dataGrid tutorials as I go but am worried that these things are just too sensitive.

Any help you can give will be appreciated. Thanks,
Larry

dickey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 118
Joined: Wed Apr 08, 2009 11:54 pm

Re: Strange DataGrid behavior

Post by dickey » Mon Dec 21, 2009 7:49 am

Hello lohill,

No promises that my reply will help you, however I have explored some of the issues you currently face. See topic http://forums.runrev.com/phpBB2/viewtop ... 264#p13264 for a discussion on these matters.

As I understand your requirements, you are attempting to display summary information for the currently selected record in your main Data Grid. The fact that you have attempted to solve the problem by placing a second grid next to the first and to syncronize scrolling between grids is exactly where I found myself too. It did seem the obvious workaround. I'm guessing too that if you were able to freeze the display of certain columns to the right or left of your main grid (akin to freeze columns in Excel) the summary columns would remain visible, and would negate the need for the second grid altogether. That would have worked for me too. Unfortunately, as wonderful as the DataGrid is, it does not allow you at this time to freeze the display of particular columns.

I had a similar experience to you when trying to get two DataGrids to syncronize scrolling (I cannot help you further there as I did not get it working), however that forced me to a rethink of what I was attempting to design for the users.

The user interface I came up with in the end was a little more compact and usuable in the end, and has had solid user endorsement.

I created a kind of "head up display" by placing a collection of fields (key information, summary calculations etc) at the top of the data grid, with formatting that draws the eye to that space (color hilites, larger fonts etc).

I then simply placed in the script of the Data Grid:

Code: Select all

on selectionChanged pHilitedIndex, pPrevHilitedIndex
    put pHilitedIndex into field "fieldHilitedIndex"
    put the dgDataOfIndex [ pHilitedIndex ] of me into tSelectedData
    put theSelectedData["Col 4"] into field "fldSummaryField1" -- and do whatever calculation you need on the fly
    put theSelectedData["Col 5"] into field "fldSummaryField2" -- and do whatever calculation you need on the fly
    put theSelectedData["Col 6"] into field "fldSummaryField3" -- and do whatever calculation you need on the fly
end selectionChanged


so whenever the selected changed, the key data and analysis appears in the 'head up' display. This seems to keep the user focused on task, and if you have many Data Grid columns, having to continually scroll to the right to review the contents of a column, it is a great time saver to present a summary in this manner.

I hope this helps,

Merry Christmas - Andrew

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Re: Strange DataGrid behavior

Post by lohill » Mon Dec 21, 2009 11:08 pm

Andrew,

Thank you for the reply and a Merry Christmas to you too. I especially thank you for the reference to the exchanges on virtually the same things that you had with Trevor. I am too new to Rev and this forum to have a feeling of who the 'movers and shakers' are. In retrospect I wish I had entitled my thread 'DataGrid as Experienced by a Strange User'. I am confident that it is going to be very useful and that I just have to learn how to use it correctly.

I gather from the exchange with Trevor that I probably should probably not attempt scrolling two grids in conjunction with each other and that your idea of putting summary data in separate fields will be the easiest. I do need to know however whether or not I can use a DataGrid as an element in the background of as series of cards with each grid containing different sets of similar data. My project is to write a Portfolio Manager program where each card in the stack represents a portfolio of stocks each of which are different from the other in data elements only. Each card will also contain some summary information in regular fields. There will also be a card for an over all summary along with card that import and export transactions. I intend to add functionality for getting current prices.

I'm still in the REV learning stage and am just experimenting with the possibilities.

Regards,
Larry

dickey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 118
Joined: Wed Apr 08, 2009 11:54 pm

Re: Strange DataGrid behavior

Post by dickey » Tue Dec 22, 2009 12:19 am

Hello Larry,

I have been approaching a different analysis task in the similar manner by creating a tabbed interface, setting up the first card with a Data Grid (checking behave like a background) in the property inspector, and then creating as many tabs/cards/grids as I require, each with different data (in your case different portfolio data).

A good learning resource for the tabbed interface and and backgrounds entitled Window Objects (cards, stacks and backgrounds) is available at http://support.runrev.com/tutorials/vid ... bjects.pdf . (Laughing) I looked at that particular tutorial so many times I still remember the part most relevant starts on page 8.

I have been using Revolution only a couple of months (although I do have a development background), and would encourage you to persevere, as it is well worth it.

Back to the head up display for a moment. Once I had my tabbed interface, with a Data Grid on each card, and the head up or summary display working for each I simplified a little further by making the head up display / summary area a modal window (see the Users Guide .pdf search page 95), so that users could toggle it on or off depending based on personal preference.

Compared to what I may have otherwise achieved in the time in another development environment, I am very happy.

I hope this helps, Larry.

Kind regards, Andrew

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Re: Strange DataGrid behavior

Post by lohill » Tue Dec 22, 2009 8:19 pm

To Trevor in particular but anyone else with opinions is OK too,

Being the stubborn person that I am I still am trying to create a stack of multiple cards with a grid on each one but with different data in each grid. My experimentation starts with a single card with one dataGrid and one button designed to load data into the grid. It starts with a blank grid and the button has the following code:

Code: Select all

on mouseUp
   answer file "Select the .TXT file to load:"
   put it into theFile
   put URL("file:" & theFile) into myData
   If the first word of myData is  "Ticker" then
      put line 1 of myData into myCols
      replace tab with return in myCols
      set the dgProp["columns"] of group "DataGrid 1" to myCols
      put true into firstLineContainsHeaders
      set the dgText[firstLineContainsHeaders] of group "DataGrid 1" to myData
   else
      answer error "Data appears to be in wrong format." with "OK" titled "Load Portfilio Data"
      end if
end mouseUp
As a single card stack I can press the button and load the data from one of my 3 previously prepared .txt files . I can, in fact, load any one of the files to that grid without any problems. Since I want to be able to load the the the data to three different cards separately, the first thing I tried to do was to group my dataGrid and button and have them behave like a background. Creating a new card produced a card with the button and an empty grid. Pressing the button to load data however is when I began to see strange things. I would end up with headings on one card and data in another. This is what prompted my initial post since it was not expected.

Now I have un-grouped the button and grid and starting with one card I have simply copied and pasted the button and grid onto the new card. This gives me a card which has all the data from the first card in the grid. Now when I press the button to load a new set of data it is successful and nothing strange happens to the first card. A similar thing happens with the third card and I have ended up with what I want - multiple cards with the exact same look and feel but with different data. They even have the ability to sort and resize columns independently of each other which is perfect.

My question is now this. Am I going to be able to continue in this manner without getting myself in some kind of trouble I can't overcome? I am going to want to add and delete rows, modify numbers in various grid cells, summarize columns of data in each of these cards, all independently of each other. If I address a specific card and grid on that card can I make it do what I want it to without affecting the grids on the other cards?

Thanks in advance,
Larry

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Re: Strange DataGrid behavior

Post by lohill » Mon Dec 28, 2009 7:20 pm

Andrew said in another thread:
In the end were you able to retrieve the values you wanted from the Data Grid?

In reference to your other post viewtopic.php?f=8&t=4588, the approach of creating a grid as a background, then creating multiple cards with that background, and displaying different data in each grid is sound. I have used that approach extensively over the last two months.
In answer to your first question: Yes, thanks to your help and patience, I have put together enough tests to convince myself that I will be able to use the DataGrid effectively when I get down to working on my project.

With regard to the second part above, I have not succeeded in being able to create a DataGrid as part of my background and then creating several cards with different data in then. At least when I try to load the data from text files using the script I showed above. I have three tab delimited text files that contain headings and data for three different portfolios. I have checked to make sure that the heading line of each matches the others. If my stack contains one card and one button with the script to load the data, I can alternately load any one of the three sets of data into that card.

After a 'load', card one contains both column headers and data. If I make a new card, I get one with an empty DataGrid (this is the case where the DataGrid was already part of the background). Pressing the load button on the new card lets me pick a different file to load. When the script is finished for this load, the new card has new data in it but has nothing in the Header row. When I go back to the first card, it has its header row but all of the data is missing. Similarly if I create a third card and load its data, I end up with good data in that card, no data in either of the two previous cards and headings only in the first card.

As mentioned earlier, I discovered that if I did NOT make the DataGrid part of the background but just simply copied it onto the new card and then filled it with the load button, that I could get all three cards loaded with proper data and proper headings. This is what led me to my question of whether or not the 'Copy' method was the way to go. The only other thing I can think of is that something in my load script was causing the 'Background' method not to function properly. My preference would be to use the Background' method since a copy and paste as part of a NewCard event seem a little messy.

Any suggestions will be appreciated,
Regards, Larry

Post Reply