Adding multiple lines to a Data Grid

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
buchacho
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 50
Joined: Fri Jun 14, 2013 10:22 pm

Adding multiple lines to a Data Grid

Post by buchacho » Thu Aug 08, 2013 1:37 am

I am trying to add data to an existing data grid. The user would specify a text file with tab delimited data, and this data would then be appended to the data grid. The approach I took was to first put the data into a temporary data grid (MainGridTemp) and then put the data into an array and then use dispatch "AddData" to append the data to MainGrid. My code works up to the point of adding data from the file to the temp grid array, but it just puts a blank line into the final grid array.

Here is my code:

Code: Select all

   --Get data from file
   answer file ""
   put empty into theData
   put url ("file:" & it) into theData
   if theData is empty then break

   --put data in a temp (hidden) data grid
   set the dgText of group "MainGridTemp" to theData

   --put formatted data into an array
   put the dgData of group "MainGridTemp" into gridArray

   --add data to data grid
   dispatch "AddData" to group "MainGrid" with gridArray
There may be a better/simpler approach to doing this...

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10364
Joined: Wed May 06, 2009 2:28 pm

Re: Adding multiple lines to a Data Grid

Post by dunbarx » Thu Aug 08, 2013 3:09 am

Hi.

I did not look at your code, but why populate another dataGrid at all? You can just get the dgData of your DG, append to that, and set the dgData back. The dataGrid will automatically accommodate the new data set, whatever its size.

Craig Newman

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

Re: Adding multiple lines to a Data Grid

Post by Klaus » Thu Aug 08, 2013 11:21 am

Hi buchacho,

what type is your datagrid? FORM or TABLE?

"AddData" (ONE dimensional array!) will only work with ONE new row of data,
but "AddLine" will work with multiple lines/rows.
If your DG is of type TABLE then you can use "AddLines".

And no, there is no better/simpler way to do so :-D


Best

Klaus

buchacho
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 50
Joined: Fri Jun 14, 2013 10:22 pm

Re: Adding multiple lines to a Data Grid

Post by buchacho » Thu Aug 08, 2013 8:52 pm

It is a table, so I simplified my code to:

Code: Select all

dispatch "AddLine" to group "MainGrid" with theData
No temp grid needed, though I might use one to do some format checking.

It works. Thanks!

Post Reply