Page 4 of 4
Re: CheckBox in a Grid Problem
Posted: Thu Aug 18, 2022 8:46 am
by mustafa
Hi red2
The arrangement of the FUNCTION SelectDes() <=== ok
Code: Select all
*---------------------------------------------*
Function SelecDes()
*---------------------------------------------*
STOCK->(DbGoTo( Form_1.Grid_1.RecNo))
Replace STOCK->L With ( ! STOCK->L )
Form_1.Grid_1.Save
DoMethod ("Form_1","Grid_1","Refresh")
Return
To prevent clicks outside column #1 from changing the "checkbox"?
I think it could be achieved with a Grid with Arrays , note that
the actual Sample that has been created is a "Fiction" regarding
the ==> CheckBox
Keep investigating ?
Regars
Mustafa
Re: CheckBox in a Grid Problem
Posted: Thu Aug 18, 2022 10:06 am
by mustafa
Hello look at the sample with Arrays
I think the issue of the columns is solved?
you can only press the box of the CheckBox
Regards
Mustafa
Re: CheckBox in a Grid Problem
Posted: Thu Aug 18, 2022 11:31 am
by serge_girard
Thx Mustafa !
Re: CheckBox in a Grid Problem
Posted: Thu Aug 18, 2022 3:49 pm
by Red2
Thank you Mustafa, your deep knowledge and continued help is greatly appreciated!
I understand that there are likely many ways to populate a Grid Control.
I hope to continue populating the grid with a .DBF table.
Yes, I fully understand and appreciate that we are working with "imitation" "CheckBox".
May I please ask the follow question:
Is there any way to (programmatically) determine which Column # a mouse click happens in?
(Google Spanish)
¿Hay alguna forma de determinar (mediante programación) en qué columna # ocurre un clic del mouse?
This critical information would let me limit toggling Checked and Unchecked to only Column #1 mouse clicks.
Thank you everyone for sharing your considerable expertise!
Red2
Re: CheckBox in a Grid Problem
Posted: Thu Aug 18, 2022 10:10 pm
by edk
Red2 wrote: ↑Thu Aug 18, 2022 3:49 pm
Is there any way to (programmatically) determine
which Column # a mouse click happens in?
Maybe try: GetProperty ( 'Form_1', 'Grid_1', 'CellColClicked' )
Re: CheckBox in a Grid Problem
Posted: Thu Aug 18, 2022 10:39 pm
by andyglezl
Red2 wrote: ↑Thu Aug 18, 2022 3:49 pm
This critical information would let me
limit toggling
Checked and
Unchecked to
only Column
#1 mouse clicks.
Maybe ...
COLUMNWHEN { { || .T. }, { || .F. }, { || .F. }, { || .F. }, { || .F. } }
Re: CheckBox in a Grid Problem
Posted: Fri Aug 19, 2022 2:13 pm
by mustafa
Hi Red2
As indicated by colleague edk
add the Grid_2
ONDBLCLICK WhenTest()
and add the following Procedure
Code: Select all
*--------------------------------------*
Function WhenTest
*--------------------------------------*
Local cString := ''
Local nRow , NumRecord , NumColum
nRow := Form_1.Grid_2.Value
cCell1 := Form_1.Grid_2.cell(nRow,1)
cCell2 := Form_1.Grid_2.cell(nRow,2)
cCell3 := Form_1.Grid_2.cell(nRow,3)
cCell4 := Form_1.Grid_2.cell(nRow,4)
cCell5 := Form_1.Grid_2.cell(nRow,5)
cCell6 := Form_1.Grid_2.cell(nRow,6)
NumRecord := alltrim(str(This.CellRowIndex))
NumColum := alltrim(str(This.CellColIndex))
cString += 'Cell Status!' + chr(13) + chr(10)
cString += + chr(13) + chr(10)
cString += 'Record Position: ' + NumRecord + chr(13) + chr(10)
cString += 'Column Position: ' + NumColum + chr(13) + chr(10)
IF NumColum == "1"
cString += 'Register Value: ' + alltrim(cCell1) + chr(13) + chr(10)
ENDIF
IF NumColum == "2"
cString += 'Register Value: ' + alltrim(cCell2) + chr(13) + chr(10)
ENDIF
IF NumColum == "3"
cString += 'Register Value: ' + alltrim(cCell3) + chr(13) + chr(10)
ENDIF
IF NumColum == "4"
cString += 'Register Value: ' + alltrim(cCell4) + chr(13) + chr(10)
ENDIF
IF NumColum == "5"
cString += 'Register Value: ' + alltrim(cCell5) + chr(13) + chr(10)
ENDIF
IF NumColum == "6"
cString += 'Register Value: ' + alltrim(cCell6) + chr(13) + chr(10)
ENDIF
MsgInfo ( cString )
Return
More simplified !
Code: Select all
*--------------------------------------*
Function WhenTest
*--------------------------------------*
nValue := Form_1.grid_2.value
MsgInfo(;
' CellValue: '+ Form_1.Grid_2.cell (nValue,This.CellColIndex)+ chr(13) + chr(10) + ;
' CellRow: '+ALLTRIM(STR(nValue))+ chr(13) + chr(10) + ;
' CellCol: '+ALLTRIM(STR(This.CellColIndex));
)
Return
By double clicking on any column of Grid_2 we
reports Record Position, column and item name
Regards
Mustafa
Re: CheckBox in a Grid Problem
Posted: Fri Sep 09, 2022 2:19 pm
by Red2
Hello All,
I have been mostly away for several weeks but am back.
Thanks to all of your expert help I now have a basic solution that:
1) Uses the
HMG IDE.
2) Uses a
.DBF table as the Grid's ControlSource.
3) Displays an "imitation
CheckBox" in the Grid column (that works well enough).
4) Toggles the "CheckBox"
only on mouse clicks in the
proper Grid column.
Thank you Mustafa. Using your kind example I was able to add an additional "imitation CheckBox" column.
It took me some time but I was eventually able to filter for
only mouse clicks in the "CheckBox" column.
My solution uses function
_GetGridCellData() in the Grid's
OnChange Event.
Code: Select all
// DataBrowse_BrowseStates_OnChange
#include "hmg.ch"
#include "dll.ch"
#xtranslate DllCall => HMG_CallDLL // Lock and Unlock screen
declare window DataBrowse
FUNCTION DataBrowse_BrowseStates_OnChange()
LOCAL laCell := {} // A 6-element Grid cell array: #1 = Grid Row, #2 = Grid Col, ...
LOCAL lnLockwHDL := 0 // Hdl
lnLockwHDL := GetFormHandle( "DataBrowse" ) // Lock
IF ( IsControlContextMenuDefined( "BrowseStates", "DataBrowse" ) )
// See: DataBrowse_OnInit.PRG
ReleaseControlContextMenu( "BrowseStates", "DataBrowse" )
ENDIF
IF ( IsWindowDefined( "DataBrowse" ) .AND. IsWindowActive( "DataBrowse" ) )
laCell := _GetGridCellData( GetControlIndex( "BrowseStates", "DataBrowse" ) )
// Toggle value only if one of the 2 Merge columns are clicked:
// Column 1 = The imitation "CheckBox"
// Column 2 = Field MergeState is the actual ControlSource
IF ( laCell[ 2 ] <= 2 )
IF ( ! ( DataBrowse.BrowseStates.RecNo == Recno() ) )
By_State->( DbGoTo( DataBrowse.BrowseStates.RecNo ) )
ENDIF
Replace By_State->MergeState with ( ! By_State->MergeState )
// Must update grid's display:
DoMethod ("DataBrowse", "BrowseStates", "Refresh")
ENDIF
ENDIF
DllCall( "user32.dll", DLL_OSAPI, "LockWindowUpdate", 0 ) // Unlock
RETURN Nil
QUESTION:
How can I include those
NECESSARY Grid IMAGE
.BMP files into my .EXE?
(Adding them into the Resource.RC file was not successful).
Thank you all for your expert and very kind help!!!
Red2
Re: CheckBox in a Grid Problem
Posted: Wed Sep 14, 2022 11:11 pm
by Red2
Greetings, I have had some success.
I added those 3 Grid "CheckBox" .BMP files into my project.
I simply read their contents, byte by byte, and stored the strings in my project.
My "CheckBox" implementation looks for a Column click using the Grid's OnChange Event.
There I check for a "CheckBox" Column mouse click .
More:
In my last post I used Function _GetGridCellData(). It returns an array including the clicked Cell's Row and Column.
I want the Column # to programmatically limit action to ONLY "CheckBox" column clicks.
Problem:
Testing showed that the Column # it returned was sometimes in Error.
Its return value could be 1 or 2 integers too large, roughly once in 20 to 50 tries.
No tweaking of my code could either expose a cause or fix this occasional error.
After much more investigating I came across Property, <Form>.<Control>.CellColFocused.
In my code using this Property returns a more accurate Column # value, but not always.
Additional testing eventually revealed that the value it returned was occasionally 1 or 2 integer too large.
I tried using the lowest Column # value returned by either.
Testing using this lowest column value showed that (normally) only
one of the column values was in error (high). The other was likely correct.
Unfortunately deep testing revealed some instances where BOTH returned values were too high.
Sad!
QUESTIONS:
1) Are there other Functions or Properties that return the Column # (of a Grid) clicked?
2) Is there some other Event I could creatively use (to look at a Grid Column click)?
3) Has anyone else had a similar experience?
Thank you all so much for all of your patient and kind help.
Any guidance or suggestions will be greatly appreciated!
Red2
Re: CheckBox in a Grid Problem
Posted: Thu Sep 15, 2022 6:27 am
by serge_girard
No idea!