Setting Datagrid Table Column Headings
Posted: Sun Feb 23, 2014 5:15 pm
				
				I am having trouble dynamically setting column headings on a datagrid table that I populate with the results of a database query. The sql query is entered by the user into a textfield, so the column headings cannot be set in advance since each query could request different fields in different orders. The query runs and the datagrid is populated, but I have not been able to figure out how to set the column headings. Here is my code:
Any suggestions would be appreciated.
			Code: Select all
on mouseUp
   -- check the global connection ID to make sure we have a database connection
   global gConnectionID
   if gConnectionID is not a number then
      answer error "Please connect to the database first."
      exit to top
   end if
   
   put field SQLField into tSQL  
   put revDataFromQuery(tab, cr, gConnectionID, tSQL) into tData
   
   //Couldn't even set columns successfully in advance
   //put "Name,Attempts,Success" into theFields
   //replace "," with CR in theFields
   //answer theFields
   //set the dgProp ["columns"] of group "DataGrid1" of card 3 to theFields
   
   -- 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
      put tData into field "Data"
      put tData into field "TableField1" of card 2
      
      --tried this but it didn't work
      --put revDatabaseColumnNames(tData) into theFields -- get field names from table
      --replace "," with CR in theFields
      --set the dgProp["columns"] of group "DataGrid1" of card 3 to theFields
      --put tData into field "DataGrid1" of card ID 1078
      put false into firstLineContainsColumnNames
      set the dgText [firstLineContainsColumnNames ] of group "DataGrid1" of card 3 to tData
      
   end if
end mouseUp