grid dblclick

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

User avatar
Claudio Ricardo
Posts: 367
Joined: Tue Oct 27, 2020 3:38 am
DBs Used: DBF, MySQL, MariaDB
Location: Bs. As. - Argentina

Re: grid dblclick

Post by Claudio Ricardo »

Hi... I use:

Code: Select all

Function Grid_X_On_DblClick	// Called from Grid_X OnDblClick

LOCAL nPos := GetProperty ("Win_X" , "Grid_X" , "Value")	// Get selected Row
LOCAL aArray_Item := GetProperty ("Win_X" , "Grid_X" , "Item" , nPos)	// Get array with all selected row, values
LOCAL cCellValue := ""

	cCellValue := aArray_Item [1]		// [1] = number of col i need get value ( between 1 to last col )
	
Return cCellValue
Corrige al sabio y lo harás más sabio, Corrige al necio y lo harás tu enemigo.
WhatsApp / Telegram: +54 911-63016162
franco
Posts: 818
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: grid dblclick

Post by franco »

Claudio Thanks,
I can not make work but I what use to get row column is.

Code: Select all

local Npos := form_1.grid_2.value, mitem := ''
if nPos[1]  = 2 .and. nPos[2] = 2
	// I am in row 2 column 2 .  My grid uses tables not arrays.
	// I want to know what this cell has in it  example "500" so I can compare to the table the grid is linked to before saving grid.
endif
mitem := form_1.Grid_2 "cellvalue"   ???????????
All The Best,
Franco
Canada
User avatar
Claudio Ricardo
Posts: 367
Joined: Tue Oct 27, 2020 3:38 am
DBs Used: DBF, MySQL, MariaDB
Location: Bs. As. - Argentina

Re: grid dblclick

Post by Claudio Ricardo »

If I don't misunderstand what you want is to compare the original value of the table shown in the grid, with the value after the user changed it in the grid...
If so you can try this:

Code: Select all

PUBLIC paArrayGrid := {}	// In the Main.prg
When double click in grid, first read cell value and store in public array:

Code: Select all

Function Grid_2_On_DblClick	// Called from Grid_2 OnDblClick

LOCAL nRow := GetProperty ("Form_1" , "Grid_2" , "Value")	// Get the number of selected Row with double click

	paArrayGrid := GetProperty ("Form_1" , "Grid_2" , "Item" , nRow)	// Here i store in the public array the values of all columns to selected row
											// don't matter if load from array or table Item have complete row values

	// Here is the code that enables the user to change the value of the grid...
Return Nil
When the user changed the cell value and wants to save it, you check if the new value in grid is correct before saved in table...

Code: Select all

Function Save_New_Value	

LOCAL nRow := GetProperty ("Form_1" , "Grid_2" , "Value")	// assuming it didn't change row when saving the new value
LOCAL aArray_Item := GetProperty ("Form_1" , "Grid_2" , "Item" , nRow)

	// I suppose you need compare column 2 to old value stored in public array with new value in aArray_Item
	
	Do Case		// or If Else, Switch
		Case paArrayGrid [2] == aArray_Item [2]
			// action for equal values
		Case paArrayGrid [2] <> aArray_Item [2]
			// action for different values... Etc.
	EndCase
	// Here one function to reload / refresh grid data...
Return
Sorry for my bad english or if something I did not understand :oops:
Corrige al sabio y lo harás más sabio, Corrige al necio y lo harás tu enemigo.
WhatsApp / Telegram: +54 911-63016162
franco
Posts: 818
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: grid dblclick

Post by franco »

Your english is great, we just code a bit different. What I need is not cell position but what is in cell of cell position.
In row 2 col 2 of my grid is 500 before saving.
the value in the table for grid in row 2 col 2 is 400
I NEED TO KNOW THESE 2 VALUES BEFORE SAVING THE GRID. I KNOW TABLE VALUE. i NEED A VARIABLE WITH GRID VALUE.

Code: Select all

LOCAL nPos := GetProperty ("Form_1" , "Grid_2" , "Value")	// your way of get selected row and column
Local aCell := Form_1.Grid_2.value                                   //  my way of get  selected  row and column
LOCAL aArray_Item := GetProperty ("Form_1" , "Grid_2" , "item" , nPos)	// Get array with all selected row, values
LOCAL cCellValue :=   ???        // I want a variable with what is in row 2, col 2         cCellValue should be 500                                        
                                             // the value in the table for grid in row 2 col 2 is 400
	
msgbox(npos)                     msgbox is  2  2
msgbox(aCell)                     msgbox is  2  2
msgbox(aArray_item)          msgbox is empty at this time no value shows up. I want 500
msgbox(cCellValue)  SHOULD BE 500.
I hope this makes sense
All The Best,
Franco
Canada
franco
Posts: 818
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: grid dblclick

Post by franco »

I got it finally.

Code: Select all

Local aCell := Form_1.Grid_2.value
Local cCellValue :=  Form_1.Grid_2.CellEx (aCell[1] , aCell[2]) 
All The Best,
Franco
Canada
User avatar
mol
Posts: 3720
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: grid dblclick

Post by mol »

Remember that grid.value returns array of cell position or row number
franco
Posts: 818
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: grid dblclick

Post by franco »

Yes, thanks Mol for thought.

Code: Select all

Local aCell := Form_1.Grid_2.value,   AcellValue, nOQty, nNQty
nNQty := Form_1. cCellVaGrid_2.CellEx (aCell[1] , aCell[2])
select pinv_it
Go Form_1.Grid_2.Recno               //sets the pinv_it file to grid
nQQty := pinv_it->qty
If aCell[2] = 2 .and. nOqty <> nNQty                           //grid col 2 = selling qty
          select Inv                                                        // must change inventory qty on hand.
          seek pinv_it->Item_no
          if found
             if rlock()
                replace onhand with onhand + nOQty-nNqty    // must check if odl > new or new > old first.
                unlock
             endif
         endif
endif
select pinv_it
   // continue on
All The Best,
Franco
Canada
franco
Posts: 818
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: grid dblclick

Post by franco »

I can not get former post to work.
The grid onchange always goes though calling procedure twice.
I needs more work.
All The Best,
Franco
Canada
User avatar
Claudio Ricardo
Posts: 367
Joined: Tue Oct 27, 2020 3:38 am
DBs Used: DBF, MySQL, MariaDB
Location: Bs. As. - Argentina

Re: grid dblclick

Post by Claudio Ricardo »

Sorry I did not consider that you used cell navigation, so I put nRow as in a standard grid. .oops.
I already know that it can be done both ways, it is that I have gotten used to the Set and Get property.
Corrige al sabio y lo harás más sabio, Corrige al necio y lo harás tu enemigo.
WhatsApp / Telegram: +54 911-63016162
User avatar
AUGE_OHR
Posts: 2061
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: grid dblclick

Post by AUGE_OHR »

hi,

not sure if this match what you want

When DblClick you have "This."
- This.CellRowIndex
- This.CellColIndex
- This.CellRow
- This.CellCol
so you can use "This."

Code: Select all

STATIC isRunning := .F.    // Field-wide STATIC must be on TOP of *.PRG

   ON DblClick DoEdit(This.CellRowIndex, This.CellColIndex)

PROCEDURE DoEdit(nRow, nCol)
LOCAL xVal
   IF isRunning = .T.
      RETURN
   ENDIF
   isRunning := .T.

   IF .NOT. EMPTY( nRow ) .AND. LEN( aData ) >= nRow
      xVal := aData[ nRow ] [ nCol ]
      // Do what you like
   ENDIF   
   isRunning := .F.      
have fun
Jimmy
Post Reply