Populating a DataGrid

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
cmalumphy
Posts: 5
Joined: Mon Dec 05, 2011 5:33 pm

Populating a DataGrid

Post by cmalumphy » Mon Feb 11, 2013 3:02 am

I am trying to learn how scrolling fields, table fields and datagrids work. I have been successful in putting my data into scrolling fields and table fields, but not into a datagrid. I just can't figure out the correct syntax. Can you help. Here is what I am trying. I query a database, and try to put the results into the three types of fields. The first two work, the datagrid doesn't.

Code: Select all

 
  put "....the sql...." into tSQL
   -- query the database
   put revDataFromQuery(tab, cr, gConnectionID, tSQL) into tData
   -- check the result and display the data or an error message
   if item 1 of tData = "revdberr" then
      answer error "There was a problem querying the database:" & cr & tData
   else

--Scrolling field works
      put tData into field "Data"
--Table field works
      put tData into field "TableField1" of card 2

--DataGrid doesn't work. The DataGrid name is "DataGrid1". Currently there is no error message, but nothing is populated. I am trying to follow a sample and I don't know what dgText is.
      put true into firstLineContainsColumnNames
      set the dgText [firstLineContainsColumnNames ] of group "DataGrid1" of card 3 to tData
 

end if

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Populating a DataGrid

Post by sturgis » Mon Feb 11, 2013 3:31 am

If you are grabbing the data from the database, the first line of the data most likely does not contain the column names. So the datagrid is trying to use the first row as the match for each column already defined in your database. If those columns don't exist, the data is entered but nothing shows.

If you are grabbing the data, and the order matches your pre-defined columns in the datagrid then you want [firstLineContainsColumNames] to be false so that the data is matched up based on position rather than by name.

If you have no pre-defined columns and have the first line contains column names = false, the correct number of columns will be created starting with generic names such as "col 1" etc..

If you need to set the names of the columns, you can: set the dgprop["columns"] of group 1 to tColumns -- where tColumns is a line delimited list of the column names you wish to use.

Then, if you wish to have your data matched up by name rather than position, (using firstlinecontains column names..) you would need to have a tab delimited line as the first line of the data you are inserting into the datagrid that contains the names of the columns to be matched.

Hope this makes a little sense. Datagrids can be a bit complicated at first.

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

Re: Populating a DataGrid

Post by Klaus » Mon Feb 11, 2013 1:36 pm

Hi cmalumphy,

1. welcome to the forum! :D

2. Do yourself a favour and read up some infos about DataGrids.
Load the complete DG docs (PDF) here:
http://lessons.runrev.com/s/lessons/m/datagrid/pdf
Read up some basics like syntax etc., datagrids ARE in fact a complex beasts
and you will be lost without knowing some basic stuff!

Best

Klaus

cmalumphy
Posts: 5
Joined: Mon Dec 05, 2011 5:33 pm

Re: Populating a DataGrid

Post by cmalumphy » Tue Feb 12, 2013 1:44 am

Thank you for the responses Sturgis and Klaus. Changing "firstLineContainsColumnNames" to false was all I needed to do. It then worked very well.

Post Reply