Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checkbox added to grid is invisible until clicked

Sydney Savoy

Programmer
Joined
Jan 15, 2024
Messages
5
Location
CA
I've been tasked with adding the ability to select multiple rows to a program's existing grid control, so I added a new column with a linked checkbox, patterned off (but not copied from) another grid in the same program.

I got the checkbox working all right, save for one problem: until it is clicked, the checkbox is invisible.

1749248783848.png

Clicking the checkbox once causes it to appear; you have to click it a second time to actually select or deselect it. Once selected the program does correctly remember its checked status.

It's not a matter of the checkbox having having a value of "Not Valued". Once the checkbox is checked, if I change to another row, then change back, I have to click it twice to un-check it.

The one difference I can find between this control and the working one is that when I added a new column to the existing grid, it came with a text box control. I have hidden and disabled the text box control, but I can't figure out how to actually delete it.

I can set styles or colours on the checkbox, but they don't show up, even when it's visible.
 
Last edited:
Hi,

Make sure that the SPARSE property of the column is set to .F. and that CURRENTCONTROL of that column is your checkbox.

Fwiw, please find attached demo code.

Code:
PUBLIC goForm

goForm = NEWOBJECT("frmForm")
goForm.Show

Read Events

Close all
Clear All

RETURN

**********

DEFINE CLASS chkBox AS CheckBox
    Visible = .T.
    Caption = ""
    
    PROCEDURE Click()
        DODEFAULT()
        This.Parent.Parent.Refresh()

    ENDPROC
ENDDEFINE

**********

DEFINE CLASS frmForm AS Form
    AutoCenter = .T.
    Caption = "Grid - multi selecting from cursor"
    Height = 480
    Width = 600
    MinHeight = This.Height
    MinWidth = This.Width
    Themes = .F.
    
    ADD OBJECT lblOData AS Label WITH ;
        Caption = "Cursor", ;
        Left = 12, ;
        Top = 42, ;
        Anchor = 3
    
    ADD OBJECT lblSelection AS Label WITH ;
        Caption = "Selected Records", ;
        Left = 300, ;
        Top = 42, ;
        Anchor = 3

    ADD OBJECT grdOData AS Grid WITH ;
        ColumnCount = -1, ;
        RecordSource = "curTemp", ;
        Left = 12, ;
        Top = 60, ;
        Width = 270, ;
        Height = 396, ;
        DeleteMark = .F., ;
        Anchor = 1 + 2 + 4
    
        PROCEDURE grdOData.Init()
            WITH this
                .SetAll("DynamicBackcolor", "IIF(curtemp.f3, RGB(0,125,125), RGB(255,255,255))","Column")
                .SetAll("DynamicForecolor", "IIF(curtemp.f3, RGB(255,255,255), RGB(0,0,0))","Column")
                .Column1.ReadOnly = .T.
                .Column2.ReadOnly = .T.
        
            ENDWITH 

            WITH This.Column3
                .Sparse = .F.
                .AddObject("chkSelection", "chkBox")
                .CurrentControl = "chkSelection"

            ENDWITH     
        ENDPROC

    ADD OBJECT grdResults AS Grid WITH ;
        Left = 300, ;
        Top = 60, ;
        Width = 282, ;
        Height = 396, ;
        DeleteMark = .F., ;
        Anchor = 1 + 2 + 4 + 8, ;
        Visible = .F.

    ADD OBJECT cmdSearch AS CommandButton WITH ;
        Left = 12, ;
        Top = 12, ;
        Height = 24, ;
        Width = 150, ;
        Caption = "Show Selection"
    
        PROCEDURE cmdSearch.Click()
            
            SELECT f1, f2, ALLTRIM(SUBSTR(f2,4)) + ALLTRIM(STR(f1)) as f4, Mod(f1,4) as f5, f3 FROM curTemp WHERE f3 ;
                ORDER BY 1 ;
                INTO CURSOR curTemp2
                
            IF _tally > 0

                WITH Thisform.grdResults
                    .Visible = .T.
                    .ColumnCount = -1
                    .RecordSource = "curTemp2"
                    .DeleteColumn()

                ENDWITH
            ELSE

                Thisform.grdResults.Visible = .F.

            ENDIF
            
            Thisform.Refresh()
            
        ENDPROC

    ADD OBJECT cmdReset AS CommandButton WITH ;
        Left = 300, ;
        Top = 12, ;
        Height = 24, ;
        Width = 90, ;
        Caption = "Reset"
        
        PROCEDURE cmdReset.Click()

            IF FILE("curtemp2")
                USE IN curtemp2
            ENDIF

            WITH Thisform.grdResults
                .Visible = .F.
            ENDWITH

            SELECT curtemp
            
            UPDATE curTemp SET f3 = .F.
            
            LOCATE

            Thisform.Refresh()
            
        ENDPROC

    PROCEDURE Destroy
        ThisForm.Release()
        Clear Events

    ENDPROC

    PROCEDURE Load
        CREATE CURSOR curTemp (f1 I AUTOINC NEXTVALUE 1 STEP 1, f2 C(20), f3 L)
        
        FOR i = 1 TO 1000
            INSERT INTO curTemp (f2, f3) VALUES ("T" + SYS(2015), .F. )
        
        ENDFOR

        LOCATE

    ENDPROC
ENDDEFINE
*********************************************

hth

MarK
 
Those two suggestions should get you going, but the Sparse setting is on the column that contains the checkbox.
 
Thank you very much! I had missed Sparse. I'd checked that every property on the checkbox and grid objects matched the working one, but neglected to check the column!

I was also able to successfully delete the textbox object.

The checkboxes are visible all the time now, but still require two clicks to check or un-check. That's much better than it was before, but not ideal. What am I missing?
 
That was the problem. I didn't think the small amount of code leftover from my earlier testing, which was just this:

this.ReadOnly = .F.
dodefault()

could have caused so much issue, but clearly I was mistaken!

All my issues are resolved. Thank you, everyone.
 

Part and Inventory Search

Sponsor

Back
Top