CheckBox in a Grid Problem

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

User avatar
mustafa
Posts: 1177
Joined: Fri Mar 20, 2009 11:38 am
DBs Used: DBF
Location: Alicante - Spain
Contact:

Re: CheckBox in a Grid Problem

Post 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
User avatar
mustafa
Posts: 1177
Joined: Fri Mar 20, 2009 11:38 am
DBs Used: DBF
Location: Alicante - Spain
Contact:

Re: CheckBox in a Grid Problem

Post 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
Attachments
CheckBox2.zip
(13.62 KiB) Downloaded 135 times
User avatar
serge_girard
Posts: 3420
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: CheckBox in a Grid Problem

Post by serge_girard »

Thx Mustafa !
There's nothing you can do that can't be done...
Red2
Posts: 282
Joined: Sat May 18, 2019 2:11 pm
DBs Used: Visual FoxPro, FoxPro
Location: United States of America

Re: CheckBox in a Grid Problem

Post 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
edk
Posts: 999
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: CheckBox in a Grid Problem

Post 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' )
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: CheckBox in a Grid Problem

Post 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. } }
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
mustafa
Posts: 1177
Joined: Fri Mar 20, 2009 11:38 am
DBs Used: DBF
Location: Alicante - Spain
Contact:

Re: CheckBox in a Grid Problem

Post 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
Red2
Posts: 282
Joined: Sat May 18, 2019 2:11 pm
DBs Used: Visual FoxPro, FoxPro
Location: United States of America

Re: CheckBox in a Grid Problem

Post 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
Red2
Posts: 282
Joined: Sat May 18, 2019 2:11 pm
DBs Used: Visual FoxPro, FoxPro
Location: United States of America

Re: CheckBox in a Grid Problem

Post 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
User avatar
serge_girard
Posts: 3420
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: CheckBox in a Grid Problem

Post by serge_girard »

No idea!
There's nothing you can do that can't be done...
Post Reply