Hola amigos.
Alguien tiene por hay un ejemplo donde utilize dos dbcombo, en uno selecciona el departamento, y dependiento el departamento seleccionado en el otro me muestre los municipios de ese departamento.
can you show me a Sample of 2 Combobox where 2nd Combobox depend on 1st combobox using fivewin command syntax
Sure, here's an example of how to create two comboboxes where the options available in the second combobox depend on the selection made in the first combobox using the Fivewin command syntax:
- Code: Select all Expand view RUN
#include "fw.ch"
FUNCTION Main()
DEFINE WINDOW Form_1 ;
AT 0,0 ;
WIDTH 300 ;
HEIGHT 200 ;
TITLE 'Combobox Example' ;
MAIN
DEFINE COMBOBOX Combo_1
ROW 20 ;
COL 20 ;
WIDTH 100 ;
HEIGHT 24 ;
FONT 'Arial', 10, FW_NORMAL
ADDITEMS {'Option 1', 'Option 2', 'Option 3'} TO Combo_1
END COMBOBOX
DEFINE COMBOBOX Combo_2
ROW 20 ;
COL 140 ;
WIDTH 100 ;
HEIGHT 24 ;
FONT 'Arial', 10, FW_NORMAL
ITEMS {'Sub-Option 1', 'Sub-Option 2', 'Sub-Option 3'}
END COMBOBOX
END WINDOW
ACTIVATE WINDOW Form_1
// Bind a handler to the first combobox to update the options in the second combobox
COMBO_1:Change := {|| UpdateCombo2()}
PROCEDURE UpdateCombo2()
LOCAL selectedOption := Combo_1:Value
// Clear the options in the second combobox
Combo_2:ClearItems()
// Add new options based on the selected option in the first combobox
IF selectedOption = 'Option 1'
Combo_2:AddItems({'Sub-Option 1', 'Sub-Option 2'}) TO Combo_2
ELSIF selectedOption = 'Option 2'
Combo_2:AddItems({'Sub-Option 3', 'Sub-Option 4'}) TO Combo_2
ELSIF selectedOption = 'Option 3'
Combo_2:AddItems({'Sub-Option 5', 'Sub-Option 6'}) TO Combo_2
ENDIF
RETURN
END FUNCTION
In this example, we create a window with two comboboxes, Combo_1 and Combo_2. Combo_1 has three options: Option 1, Option 2, and Option 3. Combo_2 initially has three sub-options: Sub-Option 1, Sub-Option 2, and Sub-Option 3.
We then bind a handler to Combo_1's Change event using the COMBO_1:Change := {|| UpdateCombo2()} statement. This handler, UpdateCombo2(), is called whenever Combo_1's selection changes.
Inside UpdateCombo2(), we first get the selected option from Combo_1 using Combo_1:Value. We then clear the options in Combo_2 using Combo_2:ClearItems(). Finally, we add new options to Combo_2 based on the selected option in Combo_1. In this example, if Option 1 is selected in Combo_1, Sub-Option 1 and Sub-Option 2 are added to Combo_2; if Option 2 is selected, Sub-Option 3 and Sub-Option 4 are added; and if Option 3 is selected, Sub-Option 5 and Sub-Option 6 are added.
Note that the syntax and function calls used in this example may vary depending on the version of Fivewin you are using.
#include "fivewin.ch"
function Prue_Combo()
local oDlg, cCiudad, cComuna, oComuna
local aCiudades, aComunas, aArr, nZ1, nZ2, encon,i, nZona
aArr := CrearArrays2()
aCiudades := aArr[1]
aComunas := aArr[2]
cCiudad := 'TAMARUGAL' // <----- Aqui le asigno un valor cualquier, donde quiero que se ubique
cComuna := 'COLCHANE' // <----- Aqui le asigno un valor cualquier, donde quiero que se ubique
nZ1:=0
nZ2:=0
encon:=.F.
FOR i := 1 to len(aComunas)
nZona := ascan(aComunas[i],Trim(cComuna))
IF nZona > 0
encon := .T.
nZ1:=i
nZ2:=nZona
ENDIF
NEXT i
IF !encon
MsgInfo("No lo encontro")
ENDIF
DEFINE DIALOG oDlg FROM 1,1 TO 300, 600 PIXEL TITLE "Seleccione Ciudad y Comuna"
@ 20, 10 COMBOBOX cCiudad ITEMS aCiudades SIZE 130,200 PIXEL OF oDlg ;
ON CHANGE ( oComuna:SetItems( aComunas[ AScan( aCiudades, cCiudad ) ] ), oComuna:Set( oComuna:aItems[ 1 ] ) )
@ 20,160 COMBOBOX oComuna VAR cComuna ITEMS aComunas[ 1 ] SIZE 130,200 PIXEL OF oDlg
@ 100,(300/2)-(100/2) BUTTON "Mostrar seleccionado" SIZE 100, 20 PIXEL OF oDlg ;
ACTION MsgInfo( cCiudad, cComuna )
ACTIVATE DIALOG oDlg CENTERED ON INIT (oComuna:SetItems( aComunas[ nZ1] ), oComuna:Set( nZ2 ))
return nil
Function CrearArrays2()
local aArray1 := {}, aArray2 := {}, aItems := {}, nVar, n
local aCiudades:={ { 1,'ARICA'},;
{ 2,'PARINACOTA'},;
{ 3,'IQUIQUE'},;
{ 4,'TAMARUGAL'},;
{ 5,'ANTOFAGASTA'},;
{ 49,'SANTIAGO'},;
{ 54,'TALAGANTE'} }
local aComunas:= { { 1,'ARICA'},;
{ 1,'CAMARONES'},;
{ 2,'PUTRE'},;
{ 2,'GENERAL LAGOS'},;
{ 3,'IQUIQUE'},;
{ 3,'ALTO HOSPICIO'},;
{ 4,'POZO ALMONTE'},;
{ 4,'CAMIÑA'},;
{ 4,'COLCHANE'},;
{ 4,'HUARA'},;
{ 4,'PICA'},;
{ 5,'ANTOFAGASTA'},;
{ 5,'MEJILLONES'},;
{ 5,'SIERRA GORDA'},;
{ 5,'TALTAL'} }
// Aquí se generan los nuevos Array para hacer los filtro del combobox
For n := 1 To Len(aCiudades)
aadd(aArray1, aCiudades[n,2])
nVar := aCiudades[n,1]
aItems := {}
AEval( aComunas, {|a| if(a[1] == nVar, aadd(aItems, a[2]),) } )
if( len(aItems) = 0, aadd(aItems,"Sin Valor"), nil )
aadd(aArray2, aItems)
Next
SysRefresh()
Return { aArray1, aArray2 }
Return to FiveWin para Harbour/xHarbour
Users browsing this forum: wilsongamboa and 38 guests