How to update a cell in a Data Grid table?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Posts: 230
- Joined: Thu Jul 01, 2010 11:50 am
How to update a cell in a Data Grid table?
Is there a way to update just a single cell in a Data Grid table, without updating a whole row? The documentation is typically silent on whether it's possible to update the contents of just a single cell (or maybe it is documented, just very well hidden.) The best I can figure is that I have to update a whole row at a time.
Re: How to update a cell in a Data Grid table?
The datagrid API does not support this, so you will need to update the complete row.
Re: How to update a cell in a Data Grid table?
I think of this differently.
I always extract the entirety of the DG with the dgText, do stuff in "ordinary" LC. and re-install. Thus I rarely distinguish between tasks involving one or more "cells", one or more rows or columns, or the whole shebang.
This is just laziness on my part. But my comfort zone is in LC, not in DG stuff. There is little penalty that I can see...
Surely if one is modifying the structure of the DG, then you need to do DG stuff. But if it just modifying text, I do it my way.
Craig
I always extract the entirety of the DG with the dgText, do stuff in "ordinary" LC. and re-install. Thus I rarely distinguish between tasks involving one or more "cells", one or more rows or columns, or the whole shebang.
This is just laziness on my part. But my comfort zone is in LC, not in DG stuff. There is little penalty that I can see...
Surely if one is modifying the structure of the DG, then you need to do DG stuff. But if it just modifying text, I do it my way.
Craig
-
- VIP Livecode Opensource Backer
- Posts: 163
- Joined: Tue Jan 26, 2010 10:15 pm
- Contact:
Re: How to update a cell in a Data Grid table?
Hi Michael,
You can update the content of a cell by using the SetDataOfIndex or SetDataOfLine commands of the datagrid API.
Usage:
1. By using index reference
where pIndex if the index of the line, pKey is the name of the column and pValue is the value to update
2. By using line reference
where pLine is the number of the row, pKey is the name of the column and pValue is the value to update
The usage context of SetDataOfIndex and SetDataOfLine is usually the datagrid group or row behavior, but you can use it from outside (a button outside the datagrid for example) by sending or dispatching the command to the datagrid group.
3. Example for updating the column "Product", row 3 with the new value "Product A" from a button outside the datagrid
An important thing to know with the both commands SetDataOfIndex and SetDataOfLine is you have to refresh the row once updated to have the value appear in the cell.
For doing that you have two commands: RefreshIndex (use it in conjonction with SetDataOfIndex ) or RefreshLine (use it in conjonction with SetDataOfLine)
So if we keep our example, the final code to use is:
Have a look to this lesson for more informations and a full example:
http://lessons.livecode.com/m/datagrid/ ... a-in-a-row
And to the datagrid API where SetDataOfLine, RefreshLine, SetDataOfIndex, RefreshIndex are described:
http://lessons.livecode.com/m/datagrid/ ... a-grid-api
You can update the content of a cell by using the SetDataOfIndex or SetDataOfLine commands of the datagrid API.
Usage:
1. By using index reference
Code: Select all
SetDataOfIndex pIndex, pKey, pValue
2. By using line reference
Code: Select all
SetDataOfLine pLine, pKey, pValue
The usage context of SetDataOfIndex and SetDataOfLine is usually the datagrid group or row behavior, but you can use it from outside (a button outside the datagrid for example) by sending or dispatching the command to the datagrid group.
3. Example for updating the column "Product", row 3 with the new value "Product A" from a button outside the datagrid
Code: Select all
dispatch "SetDataOfLine" to grp "MyDataGrid" with 3, "Product", "Product A"
An important thing to know with the both commands SetDataOfIndex and SetDataOfLine is you have to refresh the row once updated to have the value appear in the cell.
For doing that you have two commands: RefreshIndex (use it in conjonction with SetDataOfIndex ) or RefreshLine (use it in conjonction with SetDataOfLine)
So if we keep our example, the final code to use is:
Code: Select all
dispatch "SetDataOfLine" to group "MyDataGrid" with 3, "Product", "Product A"
dispatch "RefreshLine" to group "MyDataGrid" with 3
Have a look to this lesson for more informations and a full example:
http://lessons.livecode.com/m/datagrid/ ... a-in-a-row
And to the datagrid API where SetDataOfLine, RefreshLine, SetDataOfIndex, RefreshIndex are described:
http://lessons.livecode.com/m/datagrid/ ... a-grid-api
TheSlug
http://www.aslugontheroad.com - Tutorials, demo stacks and plugins for LiveCode
Data Grid Helper - An intuitive interface for building LiveCode's Data Grids
Excel Library- Extends the LiveCode language for controlling MS Excel
http://www.aslugontheroad.com - Tutorials, demo stacks and plugins for LiveCode
Data Grid Helper - An intuitive interface for building LiveCode's Data Grids
Excel Library- Extends the LiveCode language for controlling MS Excel
Re: How to update a cell in a Data Grid table?
Oh, the datagrid never ceases to surprise me, did not know this!
Sorry for my false posting, Michael!

Sorry for my false posting, Michael!
-
- Posts: 230
- Joined: Thu Jul 01, 2010 11:50 am
Re: How to update a cell in a Data Grid table?
Thank you Zryip TheSlug, that's exactly what I needed.