sample data grid code?
lists at mangomultimedia.com
Sat Apr 11 13:23:52 EDT 2009
On Apr 11, 2009, at 12:49 PM, sadhu at castandcrew.com wrote:
> Thank you again for your help, which is invaluable.
You are welcome.
> I am not sure where
> else I could find commands like "scrollLineIntoView"? Very
The documented APIs and properties are currently available in the
following chapter of the manual:
Of course I only added ScrollLineIntoView yesterday so if you looked
for it before that you would have been out of luck :-)
> I was able to apply much of your example code. And this leads me to
> next question, since you are being so kind with examples.
> The code (and data grids in general) are seemingly line oriented, as
> as I can tell.
Internally the data grid stores your data in a multi-dimensional
array. The first dimension of the array contains numerical indexes,
hence the references to indexes in some of the API calls. The index
value for an entry will never change over the life of the data grid
unless you delete it. The line number for an entry can change based on
sorting, the addition of additional lines, etc. Targeting specific
lines is merely a convenience in the API. Under the hood the targeted
line number is converted to an index in order to locate the data to
modify or delete.
> I want to be able to change one cell at a time. I came up
> with some code that works, but frankly it's pretty ugly. Is there a
> command like "modifyCell" ?
SetDataOfLine/SetDataOfIndex can modify single cell values.
If you want to update the value of a single cell in the table then you
use SetDataOfLine/SetDataOfIndex and pass in the name of your column
as the second parameter. Note that even though you are updating a
single cell value the entire line will be redrawn.
> Here below is some code, it takes a line out of the data grid, puts it
> into an array, deletes the original line in the grid, modifies one
> in the array, then converts the array back to a form suitable for
> "addLine", and then puts it back into the data grid in place of the
> deleted line. It would be cleaner if this could all be done in
> place, ie,
> right in the data grid itself. The data grid has 9 columns so hard
> every one is clumsy too.
> Perhaps you can suggest improvements to this? If not, no problem, I
> make this method work.
I think you will be pleased to know that we can clean this up quite a
bit. A couple of things -
1) There is no need to convert data from an array to text. The AddLine
command is available if your data is already in tab delimited format
but in your code you already have an array (theA). This means you can
use AddData rather than AddLine.
2) You can update data associated with a line without deleting it.
Here is what your code might look like based on the two points above.
put the dgdataofline of group "data grid 1" of card "data grid
card" into theA
put "foobar" into theA["col 3"]
set the dgDataOfLine of group "data grid 1" of card "data grid card"
Of course you can simplify this even further by doing the following:
dispatch "SetDataOfLine" to group "data grid 1" of card "data grid
card" with 3, "col 3", "foobar"
> And again, I am very grateful for your patience
> with me as a novice.
My pleasure. You will be an experienced pro in no time.
Blue Mango Learning Systems
www.bluemangolearning.com - www.screensteps.com
More information about the use-livecode