Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. sponsors. rss.
 From: ursula
  Where is ursula?
 jakarta
 Indonesia
 ursula
 To: Yousfi Benameur
  Where is Yousfi Benameur?
 El Bayadh
 Algeria
 Yousfi Benameur
 Tags
Subject: RE: Select multiple rows in grid
Thread ID: 232037 Message ID: 232324 # Views: 32 # Ratings: 0
Version: Visual FoxPro 9 SP2 Category: General VFP Topics
Date: Monday, June 22, 2009 6:28:26 AM         
   


Hi Mr Yousfi..

Until now, I always use procedural instead of Object Oriented, but after I modified the coding into procedural, I face some issues.. I don’t know how to add this method (mselectrecords()) at grid (ygrid). Because I usually just put methods inside “thisform” and also how to add these properties below at grid(ygrid)?

lmultiselect = .F.
nactiverow = 0
nlastrow = 0
nrecs2change = 0


I am sorry for my stupidity.

Cheers,

Ursula


> > Hi all,
> >
> > 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? So I want to allow the user to drag the rows that they want to delete (something like microsoft excel). I tried to search it and actually i got an interesting article from http://www.tek-tips.com/faqs.cfm?fid=433. But to be honest I am not really expert in Foxpro and I don't know how to add properties in the grid. So when I tried that coding, I found error message because I put the properties in the form instead of in the grid. So stupid right :( so I am waiting your help about select multiple rows in the grid.
> >
> > Thanks all
> >
> > Ursula
>
> I take the link you gave and make it works in a prg.you can try this code with a table and add a logical field named "Selected"(change the first line of prg only and the name of grid recordsource)
> the PROCEDURE mselectrecords is from its author(C.Chamberlain)
>
>
> publi yform
> use c:\___ytests\customer         &&put here the table  with adding a logical field "selected"
> 
> yform=createObject("form")
> with yform
> .width=640
> .height=340
> .caption="MultiSelect in a vfp native Grid"
> endwith
> 
> yform.addobject("ygrid1","ygrid")
> with yform.ygrid1
> .top=10
> .left=10
> .width=600
> .height=300
> .recordsource="customer"
> .autofit()
> .visible=.t.
> endwith
> 
> 
> yform.addobject("command1","ycommandbutton")
> with yform.command1
> .left=300
> .top=yform.ygrid1.height+10
> .width=60
> .height=27
> .visible=.t.
> endwith
> 
> yform.show(1)
> use
> return
> 
> DEFINE CLASS ygrid AS grid
> 	Height = 200
> 	Width = 320
> 	lmultiselect = .F.
> 	nactiverow = 0
> 	nlastrow = 0
> 	nrecs2change = 0
> 	Name = "ygrid"
> 
> 	PROCEDURE mselectrecords
> 		LOCAL lcSelected,;
> 		    lcRecordSource
> 
> 		#DEFINE VK_lSHIFT 0x10 && Relocate to a header file
> 		#DEFINE VK_lCONTROL 0x11 && Relocate to a header file
> 
> 		DECLARE INTEGER GetKeyState IN WIN32API INTEGER && Relocate to where WinAPI calls are declared
> 
> 		WITH THIS
> 		    .nActiveRow    = .ActiveRow && Assign value to class property
> 		    lcSelected = .RecordSource + [.selected] && Assign value to local variable
> 		    lcRecordSource = .RecordSource && Assign value to local variable
> 
> 		    DO CASE
> 		    CASE GetKeyState(VK_lSHIFT)    < 0    ;
> 		            OR GetKeyState(VK_lSHIFT) > 1 && Check for shift key press
> 
> 		        DO CASE
> 		        CASE .nLastRow > .nActiveRow && Last recd below current recd in grid
> 
> 		            .nRecs2Change = .nLastRow - .nActiveRow && Calculate no of recds to change
> 
> 		            REPLACE (lcSelected) WITH .T. IN (lcRecordSource) && Replace current recd
> 		            FOR i = 1 TO .nRecs2Change
> 		                REPLACE (lcSelected) WITH .T. IN (lcRecordSource)
> 		                SKIP IN (lcRecordSource)
> 		            ENDF
> 
> 		        CASE .nLastRow < .nActiveRow && Last recd above current recd in grid
> 
> 		            .nRecs2Change = .nActiveRow - .nLastRow && Calculate no of recds to change
> 		            REPLACE  (lcSelected) WITH .T. IN (lcRecordSource) && Replace current recd
> 		            
> 		            GO .nLastRow IN (lcRecordSource) && Goto the last recd        
> 		            FOR i = 1 TO .nRecs2Change
> 		                REPLACE (lcSelected) WITH .T. IN (lcRecordSource)
> 		                SKIP IN (lcRecordSource)
> 		            ENDF
> 		        ENDC
> 
> 		        .lMultiSelect = .T.
> 
> 		    CASE GetKeyState(VK_lCONTROL) < 0 ;
> 		            OR GetKeyState(VK_lCONTROL) > 1 && Check for control key press
> 
> 		        REPLACE (lcSelected) WITH .T. IN (lcRecordSource)
> 
> 		        .lMultiSelect = .T.
> 
> 		    OTHERWISE && Neither shift or ctrl pressed
> 		        DO CASE
> 		        CASE .lMultiSelect    
> 		            REPLACE (lcSelected) WITH .F. ;
> 		                ALL IN (lcRecordSource) && Update all recds
> 		        CASE .nLastRow    # 0
> 		            TRY
> 		                GO .nLastRow IN (lcRecordSource)
> 		            CATCH
> 		                GO BOTTOM IN (lcRecordSource)
> 		            ENDTRY            
> 		            REPLACE (lcSelected) WITH .F. IN (lcRecordSource)    
> 		        ENDCASE
> 
> 		        GO .nActiveRow IN (lcRecordSource) && Change new value
> 		        REPLACE (lcSelected) WITH .T. IN (lcRecordSource)
> 
> 		        .lMultiSelect = .F.
> 		    ENDC
> 
> 		    IF RECCOUNT(lcRecordSource) > 0
> 		        DO CASE && Set colours according to OS
> 		        CASE UPPER(OS(1)) = [WINDOWS 5.00] && Win 2K
> 		            .SetAll([DynamicBackColor]    ,;
> 		                "IIF(&lcSelected        ,;
> 		                    RGB(10,36,106)        ,;
> 		                    RGB(255,255,255))"    ,;
> 		                    [Column])
> 		        CASE UPPER(OS(1)) = [WINDOWS 5.01] && Win XP
> 		            .SetAll([DynamicBackColor]    ,;
> 		                "IIF(&lcSelected        ,;
> 		                    RGB(49,106,197)        ,;
> 		                    RGB(255,255,255))"    ,;
> 		                    [Column])
> 		        ENDCASE
> 
> 		        .SetAll([DynamicForeColor]    ,; && All OS
> 		            "IIF(&lcSelected        ,;
> 		                RGB(255,255,255)    ,;
> 		                RGB(0,0,0))"        ,;
> 		                [Column])
> 		    
> 		        .nLastRow = .nActiveRow && Mark current row for next time through
> 		    ENDIF
> 		ENDWITH
> 	ENDPROC
> 
> 
> 	PROCEDURE AfterRowColChange
> 		LPARAMETERS nColIndex
> 		THIS.mSelectRecords()
> 	ENDPROC
> 
> 
> ENDDEFINE
> *
> *-- EndDefine: ygrid
> 
> define class ycommandbutton as commandbutton
> caption="?"
> procedure click
> text to myvar noshow
> text to myvar noshow
> load a data environment for ex with wizard and add a logical field Selected in the table
> here the data is Customer.dbf+add one logical field named "Selected"
> click on a row and shift+click on the last row you want to selectyou have a multiline select in grid
> endtext
> messagebox(myvar,0+32+4096,"summary help")
> endproc
> enddefine
> 

>
>
> Dont rate please.its only for the pleasure to help.Give me only a feed back.
> Yousfi Benameur



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