Fill data from dbf file in grid combobox control

HMG Samples and Enhancements

Moderator: Rathinagiri

Post Reply
drz
Posts: 6
Joined: Thu Dec 06, 2012 4:00 pm

Fill data from dbf file in grid combobox control

Post by drz » Thu Nov 09, 2017 4:34 pm

Hi everyone,
I can not figure out how to fill data from dbf file to a combobox defined in grid control. All smples are only using fixed strings from table; but i need to choose a record from dbf file, linked to grid.

Thanks in advance for possible hint or solution.

User avatar
mol
Posts: 2856
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 125 times
Been thanked: 65 times
Contact:

Post by mol » Thu Nov 09, 2017 5:16 pm

If you use grid to display database, your current row contains one value per each field. So, what do you want to display in combobox?

drz
Posts: 6
Joined: Thu Dec 06, 2012 4:00 pm

Post by drz » Thu Nov 09, 2017 6:44 pm

One of fields has a reference to another table which contetn i woukd like to edit in a combobox control.

User avatar
gfilatov
Posts: 516
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Has thanked: 7 times
Been thanked: 61 times
Contact:

Post by gfilatov » Thu Nov 09, 2017 7:09 pm

drz wrote:
Thu Nov 09, 2017 6:44 pm
One of fields has a reference to another table which contetn i woukd like to edit in a combobox control.
Hello,

Please take a look for the following interesting sample:

Code: Select all

/*
   GRID with diferential COMBOBOX at same column
   By Pablo Cйsar on 17th March, 2017
*/

#include "hmg.ch"

Function Main
PRIVATE aRows [20][3]

aRows  [1]  := { 113.12, date(),   1,  1, .t. }
aRows  [2]  := { 123.12, date(),   2,  2, .f. }
aRows  [3]  := { 133.12, date(),   3,  3, .t. }
aRows  [4]  := { 143.12, date(), "A",  4, .f. }
aRows  [5]  := { 153.12, date(),   2,  5, .t. }
aRows  [6]  := { 163.12, date(),   3,  6, .f. }
aRows  [7]  := { 173.12, date(), "B",  7, .t. }
aRows  [8]  := { 183.12, date(),   2,  8, .f. }
aRows  [9]  := { 193.12, date(), "A",  9, .t. }
aRows [10]  := { 113.12, date(),   1, 10, .f. }
aRows [11]  := { 123.12, date(),   2, 11, .t. }
aRows [12]  := { 133.12, date(), "C", 12, .f. }
aRows [13]  := { 143.12, date(),   1, 13, .t. }
aRows [14]  := { 153.12, date(),   2, 14, .f. }
aRows [15]  := { 163.12, date(),   3, 15, .t. }
aRows [16]  := { 173.12, date(),   1, 16, .f. }
aRows [17]  := { 183.12, date(), "B", 17, .t. }
aRows [18]  := { 193.12, date(),   3, 18, .f. }
aRows [19]  := { 113.12, date(),   1, 19, .t. }
aRows [20]  := { 123.12, date(),   2, 20, .f. }

DEFINE WINDOW Form_1 ;
    AT 0,0 ;
    WIDTH 600 ;
    HEIGHT 430 ;
    TITLE 'Mixed Data Type Grid Test' ;
    MAIN NOSIZE NOMAXIMIZE

    DEFINE STATUSBAR FONT "Courier New" SIZE 9
        STATUSITEM PadC("Try by clicking at 3rd column and see the ComboBox items",84)
    END STATUSBAR

    @ 10,10 GRID Grid_1 ;
        WIDTH 576 ;
        HEIGHT 330 ;
        HEADERS {'Column 1','Column 2','Column 3','Column 4','Column 5'} ;
        WIDTHS {120,120,120,120,70} ;
        ITEMS aRows ;
        EDIT ;
        JUSTIFY { GRID_JTFY_RIGHT,GRID_JTFY_CENTER,GRID_JTFY_RIGHT,GRID_JTFY_RIGHT, GRID_JTFY_LEFT } ;
        ON CHANGE ChngCombo() ;
        COLUMNCONTROLS { {'TEXTBOX','NUMERIC','$ 999,999.99'} , {'DATEPICKER','DROPDOWN'} , {'TEXTBOX'}, { 'SPINNER' , 1 , 20 } , { 'CHECKBOX' , 'Yes' , 'No' } } ;
        COLUMNVALID {{ || .T.},{ || .T.},{ || Valid3()},{ || .T.},{ || .T.}} ;
        CELLNAVIGATION
    
END WINDOW
CENTER WINDOW Form_1
ACTIVATE WINDOW Form_1
Return Nil

Function ChngCombo()
LOCAL x, xValue, r, c:=This.CellColFocused

If c=3
   r:=This.CellRowFocused
   x:=GetControlIndex("Grid_1","Form_1")
   xValue:=aRows[r,c]
   If ValType(xValue)="C"
      _HMG_SYSDATA [ 40 ] [ x ] [ 2 ] [ c ]:={'COMBOBOX',&("GetComboItems"+"0003"+"()")}
   Else
      _HMG_SYSDATA [ 40 ] [ x ] [ 2 ] [ c ]:={'COMBOBOX',&("GetMyItems()")}
   Endif
Endif
Return Nil

Function Valid3()
LOCAL lRet:=.F.
LOCAL c:=This.CellColFocused
LOCAL r:=This.CellRowFocused
LOCAL xValue:=This.CellValue

If !Empty(This.CellValue)
   lRet:=.T.
   aRows[r,c]:=xValue
Endif
Return lRet

Function GetMyItems()
Return {'1','2','3'}

Function GetComboItems0003()
Return {'A','B','C'}
Hope that give you an idea :idea:
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein

drz
Posts: 6
Joined: Thu Dec 06, 2012 4:00 pm

Post by drz » Fri Nov 10, 2017 10:24 am

Hi Gregor,
sample you posted still use character array for combo BUT ... if i modify function by filling datat from database then it will do the tric. So thank you for solving my problem :)

Post Reply