> 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
>
>
> >
> > 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
Hi Ursula
i send you in the zip below a visual form and visual class and a dbf to run the code
at your conveniency.Run the form from its folder (set defa to ...)
Good luck
http://www.foxite.com/uploads/2a63fec9-7e33-4007-befd-b3ef84e7afd9.zipDont rate please.its only for the pleasure to help.Give me only a feed back.
Yousfi Benameur