Add grid object

Hi Experts
I am using the following code to add an object to grid column. Which works fine , but if loose the focus to this form and when regain the focus I have an error saying grid text1 is not available. So I would like to check if Command1 object exist for Grid1 one every time I refresh the Grid. Is there any command ofr it ?

      With Thisform.GRID1.Columns(6)
            .RemoveObject("Text1")
            .AddObject("Command1","CHECKBOX")
            .Command1.Caption = 'Delete this Item'
            .Sparse = .F. && show the same button on all rows simultaneously
            .HEADER1.Caption = "Delete Icode"
            .HEADER1.Alignment = 2
            .Visible = .T.
            .READONLY = .F.
      Endwith

Thanks
BalbirlallyAsked:
Who is Participating?
 
pcelbaConnect With a Mentor Commented:
You can use old and good TYPE()

With Thisform.GRID1.Columns(6)
   IF TYPE(".Text1") = "O"
            .RemoveObject("Text1")
            .AddObject("Command1","CHECKBOX")
            .Command1.Caption = 'Delete this Item'
            .Sparse = .F. && show the same button on all rows simultaneously
            .HEADER1.Caption = "Delete Icode"
            .HEADER1.Alignment = 2
            .Visible = .T.
            .READONLY = .F.
   ENDIF
Endwith

Another option is PEMSTATUS() function:
PEMSTATUS(Thisform.GRID1.Columns(6), "Text1", 5)  && returns .T. if Text1 exists.
0
 
pcelbaCommented:
BTW, this Grid adjustment should be done in Init method only to ensure it is called just once. Another possibility is to call it when you change the RecordSource property.
0
 
CaptainCyrilConnect With a Mentor Founder, Software Engineer, Data ScientistCommented:
If you build the grid again and again differently, you can kill all its columns and create new ones.

oGrid.ColumnCount = 0

If there are no major changes then I would put it in Init and do it once. Once updated, you call GO TOP and oGrid.Refresh and that will solve the Refresh.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.