Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. sponsors. rss.
 From: Stefan Wuebbe
  Where is Stefan Wuebbe?
 Hamburg
 Germany
 Stefan Wuebbe
 To: Marcia Akins
  Where is Marcia Akins?
 Akorn
 Ohio - United States
 Marcia Akins
 Tags
Subject: RE: Select multiple rows in grid
Thread ID: 232037 Message ID: 232248 # Views: 55 # Ratings: 2
Version: Visual FoxPro 9 SP2 Category: General VFP Topics
Date: Saturday, June 20, 2009 6:48:00 PM         
   


> 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




COMPLETE THREAD
Select multiple rows in grid Posted by ursula @ 6/19/2009 7:20:47 AM
RE: Select multiple rows in grid Posted by kulwant singh @ 6/19/2009 8:08:59 AM
RE: Select multiple rows in grid Posted by ursula @ 6/19/2009 8:18:30 AM
RE: Select multiple rows in grid Posted by Stefan Wuebbe @ 6/19/2009 8:40:01 AM
RE: Select multiple rows in grid Posted by ursula @ 6/19/2009 9:53:22 AM
RE: Select multiple rows in grid Posted by Stefan Wuebbe @ 6/20/2009 10:58:23 AM
RE: Select multiple rows in grid Posted by ursula @ 6/22/2009 5:48:42 AM
RE: Select multiple rows in grid Posted by Marcia Akins @ 6/20/2009 3:40:58 PM
RE: Select multiple rows in grid Posted by Stefan Wuebbe @ 6/20/2009 6:48:00 PM
RE: Select multiple rows in grid Posted by Yousfi Benameur @ 6/21/2009 2:31:09 AM
RE: Select multiple rows in grid Posted by ursula @ 6/22/2009 3:41:34 AM
RE: Select multiple rows in grid Posted by ursula @ 6/22/2009 6:28:26 AM
RE: Select multiple rows in grid Posted by Stefan Wuebbe @ 6/22/2009 9:07:40 AM
RE: Select multiple rows in grid Posted by Yousfi Benameur @ 6/22/2009 11:06:10 AM
RE: Select multiple rows in grid Posted by ursula @ 6/22/2009 11:23:14 AM
RE: Select multiple rows in grid Posted by Chris Chamberlain @ 6/22/2009 11:36:09 AM
RE: Select multiple rows in grid Posted by Yousfi Benameur @ 6/22/2009 11:49:37 AM
RE: Select multiple rows in grid Posted by Cetin Basoz @ 6/22/2009 1:58:59 PM
RE: Select multiple rows in grid Posted by ursula @ 6/22/2009 5:39:48 PM