locked
check box disappears in grid when u come back form view of report RRS feed

  • Question

  • hi

    i have a simple text box customer and a grid to display customer in 1st column of the grid and check box in 2nd column of the grid. then i have 2 push buttons print and exit. in print i do some processing and allow the user to view the report, he can view the report and press escape to come back and key in next customer.

    the problem is

    in the grid only 2 columns. 1st columns is simple name and second column is chek box. first time chek box displays correctly, but after viewing the report instead of check box T comes in all the records of the grid.

    in my load event

    select customer,.T. AS CHK from tempgrid into cursor tempinv readwrite &&tempgrid is customer c 10 temptable to populate grid and tempgrid is always empty

    sele tempinv

    appe blank

    grids record sourcetype is 0

    grids record source is tempinv

    when user types the customer in textbox and enter

    select customer,.T. AS CHK from saletran where customer = thisform.textbox1.text into cursor temp

    select tempinv

    appe from temp

    go top

    repl all chk with .T.

    THISFORM.GRID1.RecordSourceType = 0

    THISFORM

    .GRID1.RecordSource = "TEMPINV"

    THISFORM

    .GRID1.Refresh

    first time when user keys in the customer check box is displayed correctly , user deselects some and click on print, a preview is shown, he presse

    ss escape to enter the next customer, check box is not shown but T is shown in the 2nd column of all the records in the grid.

    in print button after preview i have given

    select customer,.T. AS CHK from saletran where 1=2 into cursor temp && to show empty grid

    select tempinv

    appe from temp

    go top

    repl all chk with .T.

    THISFORM.GRID1.RecordSourceType = 0

    THISFORM

    .GRID1.RecordSource = "TEMPINV"

    THISFORM

    .GRID1.Refresh

    check box is displaying correctly so i have given every thing sparse property etc. even again in print button i am setting sparse property to .f. but still not working properly. can anybody pls help me.


    Lakshmi

    Saturday, November 10, 2012 6:29 AM

Answers

  • Why do you need to reset RecordSource? Set it once in the property sheet and don't touch in your code. If you want to change that cursor that drives the grid, zap in that course and append from the temp cursor. Don't reset record source for the grid if you want to avoid headaches.

    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog

    Sunday, November 11, 2012 6:10 AM
  • You can check for the Cancel button much more easily than using SYS(1270). When a button's Cancel property is set to .T., clicking the button causes LASTKEY() to return 27 (ESC). So all you need in the textbox.Valid is:

    IF LASTKEY() = 27  
       RETURN .T.
    ENDIF

    Tamar

    • Marked as answer by Lakshmi N Friday, November 16, 2012 3:58 AM
    Thursday, November 15, 2012 9:10 PM
    Answerer
  • This is a separate problem so better to use a new thread, but this is the method I have added to my form class called CancelValidation

    local llReturn, loObject
    local array laMouseObj[1]
    
    amouseobj(laMouseObj,1) && object under mouse
    loObject = laMouseObj[1,1]
    
    if vartype(m.loObject) = "O"
    
       llReturn = thisform.releasetype = 1 or ;
          (inlist(lower(justext(sys(1272, m.loObject))),"abortbutton", "cmdclose") ;
          and mdown()) && We're checking for Release type and Close button
    else
       llReturn = thisform.releasetype = 1
    endif
    
    return m.llReturn
    

    So, in the valid event you do

    if thisform.CancelValidation()

       return 

    endif

    ** The rest of your validation code


    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog

    • Marked as answer by Lakshmi N Friday, November 16, 2012 3:58 AM
    Thursday, November 15, 2012 9:29 PM
  • Just set  exit button's cancel property to .t. and add following code in the beginning of txtbox's valid event.

     Local Obj 
     Obj=Sys(1270) 
     If VARType(Obj.cancel)="L" .And. Obj.Cancel=.T. 
     	Return .T. 
     ENDIF 

    But I prefer lostfocus event to valid event. Because it is not strict. Through this you can intimate user that he/she is wrong and allow him/her to move to next field. In this case, you can validate the data in a form as a whole just before saving the record. 


    Thursday, November 15, 2012 11:17 AM
    Answerer

All replies

  • hi

    i have a simple text box customer and a grid to display customer in 1st column of the grid and check box in 2nd column of the grid.  then i have 2 push buttons print and exit.  in print i do some processing and allow the user to view the report, he can view the report and press escape to come back and key in next customer.

    the problem is

    in the grid only 2 columns. 1st columns is simple name and second column is chek box.  first time chek box displays correctly, but after viewing the report instead of check box T comes in all the records of the grid.

    in my load event

    select customer,.T. AS CHK from tempgrid into cursor tempinv readwrite  &&tempgrid is customer c 10 temptable to populate grid and tempgrid is always empty

    sele tempinv

    appe blank

    grids record sourcetype is 0

    grids record source is tempinv

    when user types the customer in textbox and enter

    select customer,.T. AS CHK from saletran where customer = thisform.textbox1.text into cursor temp

    select tempinv

    appe from temp

    go top

    repl all chk with .T.

    THISFORM.GRID1.RecordSourceType = 0

    THISFORM

    .GRID1.RecordSource = "TEMPINV"

    THISFORM

    .GRID1.Refresh

    first time when user keys in the customer check box is displayed correctly , user deselects some and click on print, a preview is shown, he presse

    ss escape to enter the next customer, check box is not shown but T is shown in the 2nd column of all the records in the grid.

    in print button after preview i have given

    select customer,.T. AS CHK from saletran where 1=2 into cursor temp  && to show empty grid

    select tempinv

    appe from temp

    go top

    repl all chk with .T.

    THISFORM.GRID1.RecordSourceType = 0

    THISFORM

    .GRID1.RecordSource = "TEMPINV"

    THISFORM

    .GRID1.Refresh

    check box is displaying correctly so i have given every thing sparse property etc.  even again in print button i am setting sparse property to .f.  but still not working properly.   can anybody pls help me.


    Lakshmi

    • Merged by Naomi N Sunday, November 11, 2012 6:12 AM Same question
    Saturday, November 10, 2012 6:26 AM
  • THISFORM.GRID1.RecordSourceType = 0
    THISFORM.GRID1.RecordSource = "TEMPINV" 

    1) Don't set these properties at runtime. Set them at design time itself.

    or

    2) Set column1.CurrentControl to  Check1 each time you set grid's recordsource property.

    Saturday, November 10, 2012 9:13 AM
    Answerer
  • Why do you need to reset RecordSource? Set it once in the property sheet and don't touch in your code. If you want to change that cursor that drives the grid, zap in that course and append from the temp cursor. Don't reset record source for the grid if you want to avoid headaches.

    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog

    Sunday, November 11, 2012 6:10 AM
  • hi

    it is design time itself.  in load event i am not saying thisform.grid1.recordsourcetype = 0 and thisform.grid1.recordsource = "tempinv"

    i am setting in the property itself.

    in load event

    select * from tempgrid into cursor tempinv  (tempgrid is a temp empty table with customer c(10), and chk logical)

    sele tempinv

    go top

    appe blank

    repl all chk with .T.

    i am setting at properties window recordsourcetype and recordsource  (i am not coding)

    then when the user types the customer in textbox outside the grid

    my code

    sele invno,.T. as chk from saletran group by invno where customer = this.textbox1.text into cursor temp

    sele tempinv

    dele all

    appe from dbf('temp')

    now i am setting though code

    THISFORM

    .GRID1.RecordSourceType = 0

    THISFORM

    .GRID1.RecordSource = "TEMPINV"

    THISFORM

    .GRID1.Column1.Width = 160

    THISFORM

    .GRID1.Column2.Width = 97

    THISFORM

    .GRID1.COLumn2.Sparse = .F.

    THISFORM

    .GRid1.COlumn1.ReadOnly = .T.

    THISFORM

    .GRid1.COLumn1.Enabled = .F.

    THISFORM

    .GRID1.Refresh

    upto here everything is fine.  then user deselects some invnos then clicks on print

    after printing

    again my code is

    SELECT * FROM TEMPGRID INTO DBF TEMPINV.DBF

    SELECT

    TEMPINV

    USE

    SELECT

    8

    USE TEMPINV EXCLUSIVE ALIAS TEMPINV

    GO TOP

    APPEND BLANK

    REPLACE ALL

    CHK WITH .T.

    THISFORM.GRID1.RecordSourceType = 0

    THISFORM.GRID1.RecordSource = "TEMPINV"

    THISFORM.GRID1.Column1.Width = 160

    THISFORM.GRID1.Column2.Width = 97

    THISFORM.GRID1.COLumn2.Sparse = .F.

    THISFORM.GRID1.COLumn1.HEader1.Caption = "INVOICE NO"

    THISFORM.GRID1.COLumn2.HEader1.Caption = "YES OR NO"

    THISFORM.GRId1.FontBold = .T.

    THISFORM.GRid1.FontSize = 11

    THISFORM.GRID1.FontName = "Calibri"

    THISFORM.GRid1.COlumn1.ReadOnly = .T.

    THISFORM.GRid1.COLumn1.Enabled = .F.

    THISFORM.GRID1.Refresh

    THISFORM

    .Refreshhere the problem comes, again user types another customer instead of check box T is displayed, how ever user can type T OR F still to use but i want check box.


    Lakshmi

    Thursday, November 15, 2012 7:17 AM
  • hi

    very sorry everybody.  as Naomi and Ravindra suggested i should never use

    thisform.grid1.recordsourcetype = 0 

    thisform.grid1.recordsource = "tempinv"

    anywhere in the code. 

    i should set only at design time i.e. in properites window. 

    when ever course cursor changes, i just should say thisform.grid1.refresh and or thisform.refresh.

    now it is working fine.  i am very very sorry for troubling you.  

    i have one more probelm.  i am displaying error message when users  simply press enter or enter invalid code in text box but that is causing problem.  when ever i click on exit, the code in valid event of text box fires.  so when user click on exit, the valid event of text box should not fire.  how to do this.  kindly guide me.

    Thanks


    Lakshmi

    Thursday, November 15, 2012 10:38 AM
  • Just set  exit button's cancel property to .t. and add following code in the beginning of txtbox's valid event.

     Local Obj 
     Obj=Sys(1270) 
     If VARType(Obj.cancel)="L" .And. Obj.Cancel=.T. 
     	Return .T. 
     ENDIF 

    But I prefer lostfocus event to valid event. Because it is not strict. Through this you can intimate user that he/she is wrong and allow him/her to move to next field. In this case, you can validate the data in a form as a whole just before saving the record. 


    Thursday, November 15, 2012 11:17 AM
    Answerer
  • You had to start a new thread for the different question. It will help other users.  

    Thursday, November 15, 2012 11:55 AM
    Answerer
  • You can check for the Cancel button much more easily than using SYS(1270). When a button's Cancel property is set to .T., clicking the button causes LASTKEY() to return 27 (ESC). So all you need in the textbox.Valid is:

    IF LASTKEY() = 27  
       RETURN .T.
    ENDIF

    Tamar

    • Marked as answer by Lakshmi N Friday, November 16, 2012 3:58 AM
    Thursday, November 15, 2012 9:10 PM
    Answerer
  • This is a separate problem so better to use a new thread, but this is the method I have added to my form class called CancelValidation

    local llReturn, loObject
    local array laMouseObj[1]
    
    amouseobj(laMouseObj,1) && object under mouse
    loObject = laMouseObj[1,1]
    
    if vartype(m.loObject) = "O"
    
       llReturn = thisform.releasetype = 1 or ;
          (inlist(lower(justext(sys(1272, m.loObject))),"abortbutton", "cmdclose") ;
          and mdown()) && We're checking for Release type and Close button
    else
       llReturn = thisform.releasetype = 1
    endif
    
    return m.llReturn
    

    So, in the valid event you do

    if thisform.CancelValidation()

       return 

    endif

    ** The rest of your validation code


    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog

    • Marked as answer by Lakshmi N Friday, November 16, 2012 3:58 AM
    Thursday, November 15, 2012 9:29 PM
  • hi

    thank you very much.  it works very nice.


    Lakshmi

    Friday, November 16, 2012 3:59 AM
  • hi

    thank you very much. very easy and appropriate way of doing it.


    Lakshmi

    Friday, November 16, 2012 4:00 AM