wowwwww it's perfecttttttt... Thanks a lot all.. Esp for : Stefan Wuebbe, Marcia Akins and Yousfi Benameur.. My rating for all of you.. Let me learn it.. hopefully the syntax is not really difficult for me to understand it.
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