Editable checkbox in a Grid with AllowCellSelection disabled
By Sergey - Posted on January 1st, 2008
The GridHitTest method can be used to to determine where user clicked on the grid and update checkbox accordingly. Note that checkbox status can be changed by mouse only because there's no current cell when AllowCellSelection=.F.
| This is sample code. Add error handling and adjust to your requirements as necessary. |
PUBLIC oform1 oform1=NEWOBJECT("form1") oform1.Show RETURN DEFINE CLASS form1 AS form Top = 0 Left = 0 Height = 276 Width = 504 DoCreate = .T. Caption = "Form1" ngridx = 0 ngridy = 0 Name = "Form1" ADD OBJECT grid1 AS grid WITH ; ColumnCount = 3, ; HeaderHeight = 39, ; Height = 216, ; Left = 12, ; Panel = 1, ; Top = 24, ; Width = 456, ; AllowCellSelection = .F., ; Name = "Grid1", ; Column1.Width = 134, ; Column1.Name = "Column1", ; Column2.Width = 111, ; Column2.Name = "Column2", ; Column3.Width = 62, ; Column3.Sparse = .F., ; Column3.Name = "Column3" PROCEDURE grid1.Init WITH This.Column3 .Header1.Caption = "Checkbox" .AddObject("Check1","CheckBox") .Sparse = .F. .CurrentControl = "Check1" WITH .Check1 .Alignment = 2 .Caption = "" .Name = "Check1" .Visible = .T. ENDWITH .RemoveObject("text1") ENDWITH ENDPROC PROCEDURE Load CREATE CURSOR Test ( t1 C(10), t2 C(10), l1 L) INSERT INTO Test VALUES ( "Test 1 ", "Str 1", .F.) INSERT INTO Test VALUES ( "Test 2 ", "Str 2", .T.) INSERT INTO Test VALUES ( "Test 3 ", "Str 3", .F.) INSERT INTO Test VALUES ( "Test 4 ", "Str 4", .T.) GO TOP ENDPROC PROCEDURE grid1.Click LOCAL lnRelCol, lnRelRow, lnWhere STORE 0 TO lnWhere, lnRelRow, lnRelCol This.GridHitTest(Thisform.nGridX, Thisform.nGridY, @lnWhere, @lnRelRow, @lnRelCol) IF lnWhere = 3 && Cell IF lnRelCol = 3 && column 3 This.Columns(lnRelCol).check1.Value = NOT This.Columns(lnRelCol).check1.Value ENDIF ENDIF ENDPROC PROCEDURE grid1.MouseDown LPARAMETERS nButton, nShift, nXCoord, nYCoord && Save mouse position to use in Grid.Click Thisform.nGridX = nXCoord Thisform.nGridY = nYCoord ENDPROC ENDDEFINE
Recent comments
7 hours 35 min ago
1 week 19 hours ago
4 weeks 11 hours ago
5 weeks 1 hour ago
5 weeks 2 hours ago
7 weeks 4 days ago
8 weeks 1 day ago
8 weeks 1 day ago
8 weeks 4 days ago
8 weeks 4 days ago