Print

For searching in a datagrid, here is an implementation of the datagrid's FindIndexes command. We are using this command in DGH for creating the content of its property palette from a datagrid dictionary. The properties are displayed depending of the context (datagrid form or datagrid table selected, column or form builder opened).

The command makes the usage of the “value” function, a powerful function capable of evaluating a string for rendering the corresponding value.

 

command dgh_FindIndexes pWhichDataGrid, pTheKey, pSearchType, pSearchString

   local sDataArray, foundAMatch, theFoundIndex, theIndex, tIndexValue, tNotSearch, tTheResult

   

   put the dgData of pWhichDataGrid into sDataArray

   

   if (first word of pSearchType is "not") then

      put "not " into tNotSearch

      delete first word of pSearchType

   else

      put empty into tNotSearch

   end if

   

   repeat for each key theIndex in sDataArray

      put sDataArray[theIndex][pTheKey] into tIndexValue

      

      put value(tNotSearch & "(" & quote & tIndexValue & quote && pSearchType && quote & pSearchString & quote & ")") into foundAMatch

      

      if foundAMatch then

         put theIndex into item (number of items of theFoundIndex + 1) of theFoundIndex

      end if

   end repeat

   

   if (theFoundIndex is empty) then

      put 0 into tTheResult

   else

      put theFoundIndex into tTheResult

   end if

   

   return tTheResult

end dgh_FindIndexes

 

 

 

1. pWhichDataGrid is the long id of a datagrid group

2. pTheKey is a column name

3. pSearchType accepts one of the following operators:
- is / is not
- begins with / not begins with
- ends with / not ends with
- contains / not contains
- = / > / < / >= / <= / <>

4. pSearchString is the value to find in the datagrid rows


Example:

dgh_FindIndexes the longid of grp "myDatagrid",  "Article",  "is", "box"

set the dgHilitedIndexes of grp "myDatagrid" to the result