Page 1 of 1

Adding multiple lines to a Data Grid

Posted: Thu Aug 08, 2013 1:37 am
by buchacho
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...

Re: Adding multiple lines to a Data Grid

Posted: Thu Aug 08, 2013 3:09 am
by dunbarx
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

Re: Adding multiple lines to a Data Grid

Posted: Thu Aug 08, 2013 11:21 am
by Klaus
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

Re: Adding multiple lines to a Data Grid

Posted: Thu Aug 08, 2013 8:52 pm
by buchacho
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!