Page 1 of 1

DataGrid - Problem with Refresh from code

Posted: Fri Apr 18, 2014 3:07 pm
by Simon Knight
I am attempting to build a small datagrid table to hold five or six rows of data. The final column is named "selected" and displays a value of true or false in a check box that has replaced the standard field. I have a custom column behavior that controls the data and display in the column. The code below is from a mouse up handler in the column behavor. The rule I am trying to implement is that only a single row is to be selected at any time.

Code: Select all

put the dgNumberOfLines of me into tRowCount
   repeat with RowNo = 1 to tRowCount
      setDataOfLine RowNo, "selected", false  --set all rows to false
   end repeat
   setDataOfLine the dgLine of me, "selected", true
   set the hillite of the target to true  -- Failure (1)
   dispatch "ResetList" to the dgControl of the target in 0 --Failure (2)


The code correctly updates the data, but the line at Failure(1) does not prevent the checkbox from becoming un-ticked. The line at Failure(2) wipes the display of all the data in an unrelated column and does not update the check boxes correctly. A manual refresh from the inspector does update the datagrid to reflect the values in the data array. I guess that I should not be calling ResetList from within the datagrid. So how would you approach creating a datagrid that obeys the rule of allowing one row to have a value of true displayed in a checkbox?

Re: DataGrid - Problem with Refresh from code

Posted: Fri Apr 18, 2014 3:48 pm
by Simon Knight
I replaced the code listed above with a call to a handler which is on the same card as the datagrid, the call in the column behavior is

Code: Select all

send "UpdateDG the dgData of the target, the dgline of me" to card "dbsettings" in 0


and the handler on the card :

Code: Select all

On UpdateDG pDataA, pRowNo
   lock screen
  # set all the values of selected to false
   repeat for each key tkey in pDataA
      put false into pDataA[tkey]["selected"]
   end repeat
   
   # set the row of interest to true
   put true into pDataA[pRowNo]["selected"]
   
   set the dgData of group "DbLogin" to pDataA
 
   unlock screen
end UpdateDG
It works but I am sure there is a better way.