Page 1 of 1
Grid click
Posted: Sat Mar 28, 2026 1:44 pm
by serge_girard
Hello,
I have a GRID
Code: Select all
DEFINE GRID GRID_GEN_ERRORS
ROW 50
COL 10
WIDTH 1600
HEIGHT 850
HEADERS {'ID', 'PERS', 'STATUS', 'ERROR-WARNING' }
WIDTHS {1, 70, 100, 1400 }
JUSTIFY {GRID_JTFY_LEFT, GRID_JTFY_LEFT,GRID_JTFY_LEFT, GRID_JTFY_LEFT }
CELLNAVIGATION TRUE
FONTSIZE 16
FONTNAME 'Arial'
FONTBOLD TRUE
COLUMNWHEN { {|| FALSE }, {|| FALSE }, {|| TRUE }, { || FALSE } }
COLUMNCONTROLS { { 'TEXTBOX', 'CHARACTER'}, ;
{ 'TEXTBOX', 'CHARACTER'}, ;
{ 'COMBOBOX', {'OK', 'TO DO', 'IN BEHANDELING' ,'IGNORE'} }, ;
{ 'TEXTBOX', 'CHARACTER'} }
ALLOWEDIT TRUE
ITEMS {}
END GRID
// ONDBLCLICK EDIT_GEN_ERROR_PERS()
// ONCLICK EDIT_GEN_ERROR_PERS()
Somebody knows hot to get my ID-value?
Serge
I can change third column with Combobox without a problem.
But I need to have the value of column 1 (ID) when I click or double-click on it.
I tried with This.CellRowIndex, This.CellColIndex, This.CellRow, This.CellCol but it don't give back a value.
I tried with my own function (which works fine with grids without COLUMNCONTROLS )
Code: Select all
FUNCTION Column_Value( ControlName, ParentForm , nCol )
/******************************************************/
LOCAL aRet := {}
nCol := Iif( nCol == Nil .Or. nCol == 0 , 1 , nCol )
aRet := GetProperty ( ParentForm , ControlName , 'Item' , GetProperty( ParentForm , ControlName , 'Value' ) )
RETURN( aRet [ nCol ] )
Re: Grid click
Posted: Sat Mar 28, 2026 3:06 pm
by gfilatov
Hello Serge,
Thanks for your request
Please try the following working example:
Code: Select all
#include "minigui.ch"
#define COL_CODE 1
#define COL_NAME 2
#define COL_PHONE 3
FUNCTION Main()
LOCAL aData := { ;
{ "1001", "John Doe", "(555) 111-1111" }, ;
{ "1002", "Jane Smith", "(555) 222-2222" } }
DEFINE WINDOW Main ;
AT 0, 0 ;
WIDTH 600 ;
HEIGHT 400 ;
TITLE "MiniGUI Grid Demo" ;
MAIN
@ 10, 10 GRID Grid1 ;
WIDTH 580 ;
HEIGHT 300 ;
HEADERS { "Code", "Name", "Phone" } ;
WIDTHS { 100, 200, 200 } ;
ITEMS aData CELLNAVIGATION ;
ON DBLCLICK MsgInfo( Main.Grid1.Cell(This.CellRowIndex, COL_CODE) )
@ 320, 10 BUTTON BtnAdd CAPTION "Add Customer" ;
ACTION AddCustomerRecord()
@ 320, 110 BUTTON BtnUpdate CAPTION "Update Phone" ;
ACTION UpdateCustomerPhone()
END WINDOW
Main.Center()
Main.Activate()
RETURN NIL
PROCEDURE AddCustomerRecord()
LOCAL aNewRecord, cLastCode, cNewCode
IF Main.Grid1.ItemCount == 0
MsgInfo("No records in the GRID. Adding the first record with code 1001.")
cNewCode := "1001"
ELSE
cLastCode := Main.Grid1.Cell(Main.Grid1.ItemCount, COL_CODE)
cNewCode := hb_ntos(Val(cLastCode) + 1)
ENDIF
aNewRecord := { cNewCode, "New Customer", "(555) 555-5555" }
Main.Grid1.DisableUpdate // Disable rendering for performance
Main.Grid1.AddItem(aNewRecord)
Main.Grid1.EnableUpdate // Re-enable rendering
Main.Grid1.Value := Main.Grid1.ItemCount
RETURN
PROCEDURE UpdateCustomerPhone()
LOCAL nSelectedRow, cNewPhone := "(555) 123-4567"
nSelectedRow := Main.Grid1.Value[1]
IF nSelectedRow == 0
MsgInfo("No row selected!")
RETURN
ENDIF
IF !hb_RegexMatch("^\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$", cNewPhone)
MsgInfo("Invalid phone number format! Expected formats: (555) 555-5555 or 555-555-5555.")
RETURN
ENDIF
Main.Grid1.DisableUpdate // Disable rendering for performance
Main.Grid1.Cell(nSelectedRow, COL_PHONE) := cNewPhone
Main.Grid1.EnableUpdate // Re-enable rendering
RETURN
Hope this is helpful.

Re: Grid click
Posted: Sat Mar 28, 2026 3:09 pm
by serge_girard
Thanks Grigory !
Re: Grid click
Posted: Sat Mar 28, 2026 4:05 pm
by franco
Hi Serge,
Could you use onheadclick().
I highlight the cell1 I want.
Then get cell 1`s value when I click header 1
Re: Grid click
Posted: Sat Mar 28, 2026 5:49 pm
by serge_girard
Hi Franco, maybe you can supply a sample or piece of code?
Serge
Re: Grid click
Posted: Sun Mar 29, 2026 12:12 pm
by serge_girard
Grigory,
I need grid like this: DOUBLECLICK +Column Edit...
Code: Select all
@ 10, 10 GRID Grid1 ;
WIDTH 580 ;
HEIGHT 300 ;
HEADERS { "Code", "Name", "Phone" } ;
WIDTHS { 100, 200, 200 } ;
ITEMS aData CELLNAVIGATION ;
ON DBLCLICK MsgInfo( Main.Grid1.Cell(This.CellRowIndex, COL_CODE) );
COLUMNWHEN { {|| FALSE }, {|| FALSE }, {|| TRUE } } ;
COLUMNCONTROLS { { 'TEXTBOX', 'CHARACTER'}, ;
{ 'TEXTBOX', 'CHARACTER'}, ;
{ 'TEXTBOX', 'CHARACTER'} } ;
ALLOWEDIT // gives syntax error !
I now have this working grid :
Code: Select all
DEFINE GRID GRID_GEN_ERRORS
ROW 50
COL 10
WIDTH 1600
HEIGHT 850
HEADERS {'ID', 'PERS', 'STATUS', 'ERROR-WARNING' }
WIDTHS {1, 70, 100, 1400 }
JUSTIFY {GRID_JTFY_LEFT, GRID_JTFY_LEFT,GRID_JTFY_LEFT, GRID_JTFY_LEFT }
CELLNAVIGATION TRUE
FONTSIZE 16
FONTNAME 'Arial'
FONTBOLD TRUE
COLUMNWHEN { {|| FALSE }, {|| FALSE }, {|| TRUE }, { || FALSE } }
COLUMNCONTROLS { { 'TEXTBOX', 'CHARACTER'}, ;
{ 'TEXTBOX', 'CHARACTER'}, ;
{ 'COMBOBOX', {'OK', 'TO DO', 'IN BEHANDELING' ,'IGNORE'} }, ;
{ 'TEXTBOX', 'CHARACTER'} }
ALLOWEDIT TRUE
ITEMS {}
ONCLICK ToonID()
END GRID
ONDBLCLICK doesn't work here but
ONCLICK works like double-click....! Very strange
Working only with DEFINE GRID and not with @ 50 ,10 GRID GRID_GEN_ERRORS ...
Greetings, Serge
Re: Grid click
Posted: Mon Mar 30, 2026 3:41 pm
by franco
Serge,
This is what I use.
Code: Select all
ONHEADCLICK { {|| MSGBOX('ID' }, {||'PERS' }, {|| 'STATUS' }, { ||' ' } }
OR YOURS
ONHEADCLICK { {|| ToonID() }, {||' ' }, {|| ' ' }, { || ' ' } }
With this you get the value of the selected cell. If I don`t want the value I put quotes like column 4.
Hope this helps.
When ALLOWEDIT is .T. on a double click you can edit. I think this is makes so double click won`t work for view.
Re: Grid click
Posted: Mon Mar 30, 2026 4:18 pm
by franco
I was just going over some of my sample code and ran across this I could be of use.
With this to edit you must hit enter key first. You could use any key like plus key chr(43)
COLUMNWHEN { {|| FALSE }, {|| FALSE }, ,{ || iIf(HMG_GetLastVirtualKeyDown() == 13, .T., .F.)}, { || FALSE } }
Or the plus key
COLUMNWHEN { {|| FALSE }, {|| FALSE }, ,{ || iIf(HMG_GetLastVirtualKeyDown() == 43, .T., .F.)} { || FALSE } }
Re: Grid click
Posted: Mon Mar 30, 2026 6:09 pm
by serge_girard
Thanks Franco,
I now have it working:
Code: Select all
DEFINE GRID GRID_GEN_ERRORS
ROW 50
COL 10
WIDTH 1600
HEIGHT 850
HEADERS {'ID', 'PERS', 'STATUS', 'ERROR-WARNING' }
WIDTHS {1, 70, 100, 1400 }
JUSTIFY {GRID_JTFY_LEFT, GRID_JTFY_LEFT,GRID_JTFY_LEFT, GRID_JTFY_LEFT }
ONHEADCLICK { {|| ToonID() }, {||' ' }, {|| ' ' }, { || ' ' } }
CELLNAVIGATION TRUE
FONTSIZE 16
FONTNAME 'Arial'
FONTBOLD TRUE
COLUMNWHEN { {|| FALSE }, {|| FALSE }, {|| TRUE }, { || FALSE } }
COLUMNCONTROLS { { 'TEXTBOX', 'CHARACTER'}, ;
{ 'TEXTBOX', 'CHARACTER'}, ;
{ 'COMBOBOX', {'OK', 'TO DO', 'BUSY' ,'IGNORE'} }, ;
{ 'TEXTBOX', 'CHARACTER'} }
ALLOWEDIT TRUE
ITEMS {}
ONCLICK ToonID()
END GRID
FUNCTION ToonID()
/*******************/
LOCAL cID
cID := GetCurrentID( "GRID_GEN_ERRORS", "Form_GEN_ERRORS" )
IF !EMPTY(cID)
Form_GEN_ERRORS.TB_PERS_ID.Value := strvalue(cID)
ENDIF
RETURN NIL
FUNCTION GetCurrentID( cGrid, cForm )
/****************************************/
lOCAL nRow
LOCAL aRow
nRow := GetProperty( cForm, cGrid, 'CellRowFocused' )
IF nRow <= 0
RETURN NIL
ENDIF
aRow := GetProperty( cForm, cGrid, 'Item', nRow )
RETURN aRow[2] // pers_id
Now I can change 'STATUS' with Combobox and I can doubleclick on any cell (except STATUS) and then it gives me back
the ROW I clicked and I retrieve 2nd value from row which is the ID I need for other things.
Serge
Re: Grid click
Posted: Wed Apr 01, 2026 3:16 pm
by franco
Glad you got it working
I use head click on invoicing program.
if I hclick the qty header it will give me inventory on hand of item of of currenet selected row.
Hclick price will give cost of item
On a posted finalized invoice I use description to tell how the invoice was paid.
Saves a lot of time checking.