Page 1 of 1

Instability of Grid Check Box

Posted: Thu Sep 10, 2015 4:49 pm
by Rathinagiri
I have found some instability in Grid CheckBox click event:

Please try this KISS Sample

Case Scenario 1:

1. Run this demo
2. Press TAB/ENTER to move to grid
3. Press SPACE BAR and change the checkbox value.
4 You can see that CheckBoxClicked Event is not fired!

Case Scenario 2:

1. Run this demo
2. Click on CheckBox of item 2, We have different values for nValue, nCellRowClicked and nCellRowFocused. It is right.
3. Now, move to Grid item 1 or 3 by pressing up/down arrow key
4. Press SPACE BAR and change the checkbox value
5. Now you can see that CheckBoxClicked Event IS fired! We have different values for nValue, nCellRowClicked and nCellRowFocused. nCellRowClicked is wrong IMHO.

What is expected to be done?

In whatever way we do, either by pressing Space bar or mouse click On CheckBoxClicked shall be fired and we shall have a unique value to be checked ( value/cellrowclicked/cellrowfocused) on which row the checkbox value is getting changed.

Code: Select all

#include <hmg.ch>

Function Main

   set navigation extended
   
   define window demo at 0, 0 width 400 height 300 main
   
      define textbox t1
         row 10
         col 10
         width 100
      end textbox
      define grid g1
         row 40
         col 10
         width 330
         height 100
         widths { 100, 100, 100 }
         headers { 'Head1', 'Head2', 'Head3' }
         items { { 'Cell11', 'Cell 12', 'Cell 13' }, { 'Cell21', 'Cell 22', 'Cell 23' }, { 'Cell31', 'Cell 32', 'Cell 33' } }
         oncheckboxclicked checkboxclicked()   
         value 1
      end grid
      define textbox t2
         row 150
         col 10
         width 100
      end textbox
   end window
   demo.g1.checkboxenabled := .t.
   demo.center
   demo.activate
Return


function checkboxclicked
   local nValue := demo.g1.value
   local nCellClicked := demo.g1.cellrowclicked
   local nCellFocused := demo.g1.cellrowfocused
   
   msginfo( 'Value : ' + alltrim( str( nValue ) ) + ', Cell Clicked : ' + alltrim( str( nCellClicked ) ) + ', Cell Focused : ' + alltrim( str( nCellFocused ) ) )
   return nil
 

Re: Instability of Grid Check Box

Posted: Thu Sep 10, 2015 6:40 pm
by andyglezl
Lo siento, tengo la version 3.4
-------------------------------------
Sorry, I have version 3.4


D:\HMG\3.4>build sample1
Harbour 3.2.0dev (r1501091819)
Copyright (c) 1999-2014, "http://harbour-project.org/"
sample1.prg(2494) Error E0030 Syntax error "syntax error at 'CHECKBOXCLICKED'"
1 error

Re: Instability of Grid Check Box

Posted: Thu Sep 10, 2015 8:30 pm
by Rathinagiri
You have to get 3.4.1 and all the patches (from the download page) to run this demo.

Re: Instability of Grid Check Box

Posted: Thu Sep 10, 2015 8:53 pm
by srvet_claudio
Rathinagiri wrote:I have found some instability in Grid CheckBox click event:

Please try this KISS Sample

Case Scenario 1:

1. Run this demo
2. Press TAB/ENTER to move to grid
3. Press SPACE BAR and change the checkbox value.
4 You can see that CheckBoxClicked Event is not fired!

Case Scenario 2:

1. Run this demo
2. Click on CheckBox of item 2, We have different values for nValue, nCellRowClicked and nCellRowFocused. It is right.
3. Now, move to Grid item 1 or 3 by pressing up/down arrow key
4. Press SPACE BAR and change the checkbox value
5. Now you can see that CheckBoxClicked Event IS fired! We have different values for nValue, nCellRowClicked and nCellRowFocused. nCellRowClicked is wrong IMHO.

What is expected to be done?

In whatever way we do, either by pressing Space bar or mouse click On CheckBoxClicked shall be fired and we shall have a unique value to be checked ( value/cellrowclicked/cellrowfocused) on which row the checkbox value is getting changed.

Code: Select all

#include <hmg.ch>

Function Main

   set navigation extended
   
   define window demo at 0, 0 width 400 height 300 main
   
      define textbox t1
         row 10
         col 10
         width 100
      end textbox
      define grid g1
         row 40
         col 10
         width 330
         height 100
         widths { 100, 100, 100 }
         headers { 'Head1', 'Head2', 'Head3' }
         items { { 'Cell11', 'Cell 12', 'Cell 13' }, { 'Cell21', 'Cell 22', 'Cell 23' }, { 'Cell31', 'Cell 32', 'Cell 33' } }
         oncheckboxclicked checkboxclicked()   
         value 1
      end grid
      define textbox t2
         row 150
         col 10
         width 100
      end textbox
   end window
   demo.g1.checkboxenabled := .t.
   demo.center
   demo.activate
Return


function checkboxclicked
   local nValue := demo.g1.value
   local nCellClicked := demo.g1.cellrowclicked
   local nCellFocused := demo.g1.cellrowfocused
   
   msginfo( 'Value : ' + alltrim( str( nValue ) ) + ', Cell Clicked : ' + alltrim( str( nCellClicked ) ) + ', Cell Focused : ' + alltrim( str( nCellFocused ) ) )
   return nil
 
The problem is that CellRowClicked returns always the last row in that you clicked with the mouse and not considered the clicked with keyboard.
I have implemented OnCheckBoxClicked event only with the mouse interface.

Change the original code (h_windows.prg, line 3121) for this:

Code: Select all

               //   OnCheckBoxClicked   (by Dr. Claudio Soto, December 2014)
               #define LVIS_UNCHECKED 0x1000
               #define LVIS_CHECKED   0x2000
               IF GetGridNewState(lParam) == LVIS_UNCHECKED .OR. GetGridNewState(lParam) == LVIS_CHECKED
                  xTemp := { NIL, NIL }
                  xTemp[1] := _HMG_SYSDATA [ 40 ] [ i ] [ 37 ] [ 1 ]   // This.CellRowClicked
                  IF ( xTemp[1] > 0 .AND. xTemp[1] <=  ListView_GetItemCount (_HMG_SYSDATA [ 3 ] [ i ]) ) .OR. ; 
                     ( HMG_GetLastVirtualKeyDown( @xTemp[2] ) == VK_SPACE .AND. xTemp[2] == _HMG_SYSDATA [ 3 ] [ i ] ) 
                     _DoControlEventProcedure ( _HMG_SYSDATA [ 40 ] [ i ] [ 46 ] , i )   // OnCheckBoxClicked
                     Return 0
                  ENDIF
               ENDIF

Re: Instability of Grid Check Box

Posted: Fri Sep 11, 2015 2:44 am
by Rathinagiri
Thanks a lot Claudio. I will check this and revert back.

Re: Instability of Grid Check Box

Posted: Fri Sep 11, 2015 6:44 am
by Rathinagiri
Claudio,

Thank you for the implementation. Now the event is fired even when we use the space bar.

Now, the only problem is, how to find out the CellRowIndex on which the checkbox is mouse clicked/space bar pressed. Is it cellrowclicked or cellrowfocused or value? We should have the same value either by pressing space bar or using mouse click.

Re: Instability of Grid Check Box

Posted: Fri Sep 11, 2015 9:58 am
by srvet_claudio
In the patch 7 viewtopic.php?f=43&t=4400&p=42676#p42676

I did that when you click with the Spacebar:

CellRowClicked = row of the checkbox

CellColClicked = 0

Re: Instability of Grid Check Box

Posted: Fri Sep 11, 2015 1:43 pm
by Rathinagiri
That will be really great Claudio. Thanks a lot.

Re: Instability of Grid Check Box

Posted: Sun Sep 13, 2015 7:56 am
by serge_girard
Thanks Claudio !

Serge

Re: Instability of Grid Check Box

Posted: Mon Sep 14, 2015 5:09 am
by bpd2000
Rathinagiri wrote:That will be really great Claudio. Thanks a lot.
+1