Populating Datagrid (Form) with Results of Search of SQLite

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: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
Posts: 125
Joined: Thu Jul 18, 2013 5:23 am

Populating Datagrid (Form) with Results of Search of SQLite

Post by montymay » Sat Feb 11, 2017 8:03 am

I have a SQLite database of records. Each record has 13 fields. I want to put the results of a search query into the following datagrid form, which has just six text fields and one image:
My search code is thus:

Code: Select all

global gDatabaseID
on mouseup
   put fld "query" into theSearchString
   get revDataFromQuery(tab, return, gDatabaseID, "SELECT * FROM opsDetails WHERE keys LIKE '%" & theSearchString & "%'")
   set the dgText of group "Datagrid 1" to it
end mouseup
I am using the following excerpt from the default script of the datagrid:

Code: Select all

on FillInData pDataArray
   set the text of field "Label" of me to pDataArray["label 1"]
end FillInData
When the script does the search, I see that rows of the datagrid are populated equal to the number of hits. The default label field of the datagrid form displays all 13 tab-delimited fields of each record.

However, I want my script to put the 6 pieces of text data from each record into the corresponding fields of the form. I can't find any explanation in this forum or the LC lessons on datagrids and SQLite databases. I am novice, but I sense that advanced manipulation of the array variable pDataArray is required. I not asking anyone to write my script if much work is required, but if so perhaps someone could link to a resource or point me in the right direction. Thanks so much.

Monty May

Posts: 368
Joined: Tue Jun 05, 2012 5:38 pm
Location: Alexandria, Virginia

Re: Populating Datagrid (Form) with Results of Search of SQL

Post by sritcp » Sat Feb 11, 2017 3:12 pm

Hi Monty:

Could you reproduce your actual FillinData code (where you fill in the data for each of the six fields)?


Posts: 11062
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany

Re: Populating Datagrid (Form) with Results of Search of SQL

Post by Klaus » Sat Feb 11, 2017 5:53 pm

Hi Monty,

datagrids of type FORM need a different approach than the "simple" TABLE datagids!

For a FORM you need to set "the dgdata" of your datagrid to an ARRAY!
So you need to convert the result of your quesry to a multidoimensiopnal array first.
Then you also need to use another "fillindata" handler.

Take alook at this PDF: http://lessons.livecode.com/m/datagrid/pdf and read up
"Working with Datagrid Forms"



Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”