add lines and line numbers to Datagrid

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

add lines and line numbers to Datagrid

Post by bsouthuk » Wed Apr 06, 2011 11:44 am

Hi Guys

I am trying to build a datagrid that creates the total amount of lines that is displayed in a particular field. For instance if 127 is displayed in the field then 127 lines needs to be created in the datarid table whilst adding line numbers to each line in the 'Line Number' collumn of the datagrid. There will be 3 other collumns to the datagrid but these need to be left blank allowing users to be able to click in each cell and enter data manually.

I have just started working with Datagrids and have gone through the tutorials but none can teach me how to do the above.

Can anyone help with this?

Thanks

Daniel

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

Re: add lines and line numbers to Datagrid

Post by Klaus » Wed Apr 06, 2011 1:08 pm

Hi Daniel,

so you want to create NEW data for an empty datagrid with a user defined number of lines, right?

Well, "the dgtext of grp "datagrid" is in fact nothing else but a TAB and CR delimited list,
so creating this is unbelievable easy :D

In my example here, I presume that the "linenumber" column is the FIRST column in your grid.
You are talking about three other columns, so I thing you have a total of four columns in your datagrid.
then you could do this (out of my head, not tested!).
The parameter "thenumberoflines" will be the number that your user entered (or whatever...)

Code: Select all

command createLinesInDataGrid thenumberoflines
  ## We create the data in a repeat loop, go figure :-)
   repeat with i = 1 to thenumberoflines

  ## Now we create the number for the first column and EMPTY entries for the other columns
    put i & TAB & TAB & TAB & CR after tNewData
  end repeat

  ## Get rid of last CR
  delete char - 1 of tNewData
 
  ## that's all, now "put" the new data into your datagrid
  set the dgtext of group "you datagrid name here" to tNewData
end createLinesInDataGrid
Best

Klaus

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

Re: add lines and line numbers to Datagrid

Post by bsouthuk » Wed Apr 06, 2011 2:37 pm

Brilliant thank you Klaus.

If a user was to enter some data into a cell in the 2nd collumn and they wanted the same data to be entered into the next 20 lines of that collumn, would they be able to copy the data and then highlight all cells in that collumn for the next 20 lines and then paste?

Obviously you can do this 1 at a time but that's very time consuming. I kind of want my datagrid to work like Excel if you know what I mean!

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

Re: add lines and line numbers to Datagrid

Post by Klaus » Wed Apr 06, 2011 2:52 pm

Hi Daniel,

sounds like my script did in fact work! :lol:

I am afraid you can only edit ONE "cell" at a time manually.
Of course you can do this via script.


Best

Klaus

Post Reply