Datagrid help

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
bsouthuk
Posts: 261
Joined: Fri Dec 05, 2008 7:25 pm

Datagrid help

Post by bsouthuk » Fri Nov 11, 2011 2:44 pm

Hi

I am trying to update all cells within a column in my datagrid but I cant work out how. I currently have the following code:

Code: Select all

put field "ID6" into theDataA["DealerContactID"]

put 2 into theLineNo

repeat with i = 1 to theLineNo
 dispatch "AddData" to group "MobileNumbersDataGrid" with theDataA, theLineNo
end repeat

However, this actually ADDS 2 new rows but I only want to EDIT the cells within the column of the existing rows. I have the put 2 into theLineNo code but also want it so that it updates ALL the cells within the column not just 2.

Can anyone help with this?

Thanks

Daniel

Klaus
Posts: 14213
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Datagrid help

Post by Klaus » Fri Nov 11, 2011 3:25 pm

Hi Daniel,

as the name suggests and as clearly described in the DataGrid docs, "AddData" will indeed ADD a new line to your datagrid.
Doing so in a repeat loop "with 1 to 2" will result in TWO NEW lines :shock:
8)

I am still not sure what exactly you want to do?
And please post the rest of your script, if there is any.


Best

Klaus

bsouthuk
Posts: 261
Joined: Fri Dec 05, 2008 7:25 pm

Re: Datagrid help

Post by bsouthuk » Fri Nov 11, 2011 3:29 pm

If for instance there are 20 rows of data in my datagrid, I want to be able to click a button and for the date to appear in each row of a particular column.

Thanks for your help

Klaus
Posts: 14213
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Datagrid help

Post by Klaus » Fri Nov 11, 2011 4:31 pm

Hi Daniel,

I think you need to loop through the complete datagrid array and change the value of your "DealerContactID" field if I understand you correctly.

Something like this (out of my head, NOT tested!)

Code: Select all

...
## Get the complete data
put the DGData of grp "MobileNumbersDataGrid" into tArray
put field "ID6" into tDealerContactID

## Now update every entry of DealerContactID
repeat for each key tKey in tArray
  put tDealerContactID into tArray[tKey]["DealerContactID"]
end repeat

## Set the data of the datagrid back to the now modified array
set the DGData of grp "MobileNumbersDataGrid" to tArray
...
Best

Klaus

bsouthuk
Posts: 261
Joined: Fri Dec 05, 2008 7:25 pm

Re: Datagrid help

Post by bsouthuk » Fri Nov 11, 2011 4:45 pm

Works perfectly - thank you Klaus!

Klaus
Posts: 14213
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Datagrid help

Post by Klaus » Fri Nov 11, 2011 4:46 pm

Grrrrrreat! :D

Post Reply