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.
Fill data from dbf file in grid combobox control
Moderator: Rathinagiri
Re: Fill data from dbf file in grid combobox control
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?
Re: Fill data from dbf file in grid combobox control
One of fields has a reference to another table which contetn i woukd like to edit in a combobox control.
Re: Fill data from dbf file in grid 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'}
Kind Regards,
Grigory Filatov
"Everything should be made as simple as possible, but no simpler." Albert Einstein
Grigory Filatov
"Everything should be made as simple as possible, but no simpler." Albert Einstein
Re: Fill data from dbf file in grid combobox control
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
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