>
Do you know how to select multiple rows in the grid? Is there another way if I don't want to add a field with checkbox?>
> I do not know of another way to select rows in a grid without using a logical flag (checkbox) to say that the row is selected.
>
One way might be to create a temp cursor, and in Grid.AfterRowColChange() insert the PK value of the current grid.RecordSource row.
Assumed the multi-select key would be Ctrl, then, depending on the key status, one can either Zap the temp cursor before the current row gets inserted, or let it be.
In order to display the "selected" status, a column.DynamicBackColor expression can do a Seek() in the temp cursor.
hth
-Stefan
LOCAL oForm as Form
oForm = CREATEOBJECT('TestForm')
oForm.Show(1)
RETURN
DEFINE CLASS TestForm as Form
AllowOutput = .F.
AutoCenter = .T.
DataSession = 2
PROCEDURE Load
SET DELETED ON
LOCAL i
CREATE CURSOR temp (test Int)
FOR i = 1 TO 10
INSERT INTO temp VALUES (i)
ENDFOR
GO TOP
CREATE CURSOR crsSelected (pk Int)
INDEX on pk TAG pk COLLATE 'machine'
INSERT INTO crsSelected VALUES (temp.test)
ENDPROC
PROCEDURE GetShiftKey
#DEFINE VK_CONTROL 0x11
DECLARE Short GetKeyState IN WIN32API Integer
RETURN BitTest(GetKeyState(VK_CONTROL),31)
ENDPROC
PROCEDURE ZapSelected()
LOCAL lcSafety
lcSafety = SET("Safety")
SET SAFETY OFF
ZAP IN crsSelected
SET SAFETY &lcSafety
ENDPROC
ADD OBJECT Grid1 as Grid WITH Width = 200, RecordSource = 'temp', AllowCellSelection = .F.
PROCEDURE Grid1.Init
LOCAL lcDynamicExpression
lcDynamicExpression = "IIF(SEEK(temp.test,'crsSelected','pk'), RGB(255,128,128), RGB(255,255,255))"
This.SetAll('DynamicBackColor',m.lcDynamicExpression,'Column')
ENDPROC
PROCEDURE Grid1.AfterRowColChange(nColIndex)
IF NOT Thisform.GetShiftKey()
Thisform.ZapSelected()
ENDIF
INSERT INTO crsSelected VALUES (temp.test)
This.Refresh()
ENDPROC
ADD OBJECT lblComment as Label WITH ;
Left = 10, Top = 220, AutoSize = .T., Caption = "Hold the Ctrl key to multi-select"
ENDDEFINE