Firstly the code below is my attempt at combining a couple of different threads about this particular issue. I hope by posting this it will help others.
Thanks to: zaxos, sritcp,billworld, Janschenkel and bn for their posts which guided me to the below "solution"
Basically I have a datagrid with two columns. I want the user to be able to search by the first column (EqipmentCode) by typing the search into a field (fEquipSearch).
I did away with the timer resetting the buffer as I know some of the users (including myself) would end up getting strange results as they can get distracted.
I have a problem where the "EquipmentDescription" column isn't being populated on the result of the search, but I'm sure I'll get it figured out (any help would be appreciated).
Code: Select all
local sBuffer, sTimer
on keyup pKey
put the milliseconds into sTimer
--send "clearBuffer" to me in 1000 milliseconds
put pKey after sBuffer
StartSearch
end keyup
on backspaceKey
delete char -1 of sBuffer
delete char -1 of field fEquipSearch
StartSearch
end backspaceKey
on StartSearch
PopulateEquipDG
lock screen
put sBuffer into vSearch
put the dgdata of group "DataGrid2" into vTable1
put the dgIndexes of group "DataGrid2" into vIndex1
if vSearch <> "" then -- added this because if its not there and the user has deleted the text string, the datagrid redraws with no data.
repeat for each item iIndex in vIndex1
if vTable1[iIndex]["EquipmentCode"] contains vSearch then
put vTable1[iIndex]["EquipmentCode"] after vTable2[iIndex]["EquipmentCode"]
put vTable1[iIndex]["EquipmentDescription"] after vTable2[iIndex]["EquipmentDescription"]
end if
end repeat
set the dgdata of group "DataGrid2" to vTable2
unlock screen
end if
end StartSearch
on ClearBuffer
-- -- adjust for typing speed
-- -- after 1000 milliseconds the buffer is cleared and you can type for a new selection
-- if the milliseconds - sTimer > 5000 then
put "" into sBuffer
PopulateEquipDG
--else
-- send "clearBuffer" to me in 1000 milliseconds
--end if
end ClearBuffer