DropDown ComboBox Programmatically
Moderator: Rathinagiri
DropDown ComboBox Programmatically
a ComboBox's items can be dropped by clicking on the control....
but any function / method that can be used to drop the items ?
Best Regards
Chang
but any function / method that can be used to drop the items ?
Best Regards
Chang
Just Hmg It !
-
- Posts: 1275
- Joined: Tue Sep 03, 2013 4:22 am
- Location: Tecámac, México
Re: DropDown ComboBox Programmatically
Hola hmgChang,
Ej.:
Form_1.Combo_1.AddItem("UNO")
Form_1.Combo_1.AddItem("DOS")
Form_1.Combo_1.AddItem("TRES")...
Saludos
Code: Select all
AddItem Method
Adds a New Item To a ListBox, COmboBox Or Grid
Syntax:
<ParentWindowName>.<ControlName>.AddItem (<cItem> )
<Item> type must be character for lists and combos.
Form_1.Combo_1.AddItem("UNO")
Form_1.Combo_1.AddItem("DOS")
Form_1.Combo_1.AddItem("TRES")...
Saludos
- Rathinagiri
- Posts: 5471
- Joined: Tue Jul 29, 2008 6:30 pm
- DBs Used: MariaDB, SQLite, SQLCipher and MySQL
- Location: Sivakasi, India
- Contact:
Re: DropDown ComboBox Programmatically
Yes. Just see this small sample.
Code: Select all
#include <hmg.ch>
Function Main
define window main at 0, 0 width 400 height 300 main
define button show1
row 10
col 10
caption 'Show Drop'
action combodropdown( 'main', 'combo1' )
end button
define combobox combo1
row 40
col 10
width 200
items { 'Item 1', 'Item 2', 'Item 3'}
value 1
end combobox
end window
main.center
main.activate
Return
function combodropdown( cWindowName, cControlName )
nHandle := GetControlHandle ( cControlName, cWindowName )
if nHandle > 0
ComboBoxShowDropDown( nHandle )
endif
return nil
#pragma BEGINDUMP
#include <windows.h>
#include <commctrl.h>
#include "hbapi.h"
#include <wingdi.h>
HB_FUNC ( COMBOBOXSHOWDROPDOWN )
{
HWND hWnd1;
hWnd1 = (HWND) hb_parnl (1);
SendMessage((HWND) hWnd1,CB_SHOWDROPDOWN, (WPARAM)(int) 1,(LPARAM)(int) 0);
}
#pragma ENDDUMP
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
South or North HMG is worth.
...the possibilities are endless.
- esgici
- Posts: 4543
- Joined: Wed Jul 30, 2008 9:17 pm
- DBs Used: DBF
- Location: iskenderun / Turkiye
- Contact:
Re: DropDown ComboBox Programmatically
ImpressiveRathinagiri wrote:Yes. Just see this small sample.
...
May be a way to make this little and powerful function a method ?
Something like
Code: Select all
myForm.myComboSBox.ForceDropDown()
Viva INTERNATIONAL HMG
-
- Posts: 1275
- Joined: Tue Sep 03, 2013 4:22 am
- Location: Tecámac, México
Re: DropDown ComboBox Programmatically
Hola Rathinagiri,
Bonito ejemplo!
Saludos
Bonito ejemplo!
Saludos
- Rathinagiri
- Posts: 5471
- Joined: Tue Jul 29, 2008 6:30 pm
- DBs Used: MariaDB, SQLite, SQLCipher and MySQL
- Location: Sivakasi, India
- Contact:
Re: DropDown ComboBox Programmatically
Please see this sample which I had made two years ago.
This includes showing/hiding the dropdown, incorporate autofill in combobox.
It requires a 'Countires.lst' file which shall contain the list of countries. You can use this.
This includes showing/hiding the dropdown, incorporate autofill in combobox.
Code: Select all
#include <hmg.ch>
Function Main
local aCountries := HB_ATOKENS( MEMOREAD( "Countries.lst" ), CRLF )
set navigation extended
define window x at 0,0 width 300 height 200 main
define textbox b
row 10
col 10
end textbox
define combobox a
row 60
col 10
width 100
items aCountries
sort .t.
displayedit .t.
on displaychange x.b.value := x.a.item(ComboSearchAutoFill())
end combobox
end window
x.center
x.activate
Return
function ComboSearchAutoFill
local nHandle := 0
local cValue := this.displayvalue
local nStart := 0
local nFound := 0
local cControlName := this.name
local cFormName := thiswindow.name
nHandle := GetControlHandle (this.name,thiswindow.name)
if .not. valtype(_HMG_SYSDATA [ 296 ]) == "U"
if _HMG_SYSDATA [ 296 ] > 0
if len(cValue) == _HMG_SYSDATA [ 296 ]
if len(cValue) > 1
cValue := substr(cValue,1,len(cValue)-1)
else
nFound := ComboBoxFindString(nHandle,cValue)
if nFound <> -1
this.value := nFound + 1
ComboBoxSelectString(nHandle,cValue)
ComboBoxEditSetSel(nHandle,0,-1)
_HMG_SYSDATA [ 296 ] := 0
setproperty(cFormName,cControlName,"VALUE",nFound-1)
return nFound + 1
else
ComboBoxHideDropDown(nHandle)
endif
endif
endif
endif
endif
_HMG_SYSDATA [ 296 ] := len(cValue)
nStart := len(cValue)
if nHandle > 0
nFound := ComboBoxFindString(nHandle,cValue)
if nFound <> -1
ComboBoxShowDropDown(nHandle)
this.value := nFound + 1
ComboBoxSelectString(nHandle,cValue)
ComboBoxEditSetSel(nHandle,nStart,-1)
else
ComboBoxHideDropDown(nHandle)
endif
endif
return nFound + 1
#pragma BEGINDUMP
#include <windows.h>
#include <commctrl.h>
#include "hbapi.h"
#include <wingdi.h>
HB_FUNC ( COMBOBOXSHOWDROPDOWN )
{
HWND hWnd1;
hWnd1 = (HWND) hb_parnl (1);
SendMessage((HWND) hWnd1,CB_SHOWDROPDOWN, (WPARAM)(int) 1,(LPARAM)(int) 0);
}
HB_FUNC ( COMBOBOXHIDEDROPDOWN )
{
HWND hWnd1;
hWnd1 = (HWND) hb_parnl (1);
SendMessage((HWND) hWnd1,CB_SHOWDROPDOWN, (WPARAM)(int) 0,(LPARAM)(int) 0);
}
HB_FUNC ( COMBOBOXEDITSETSEL )
{
HWND hWnd1;
hWnd1 = (HWND) hb_parnl (1);
hb_retni(SendMessage((HWND) hWnd1,CB_SETEDITSEL, (WPARAM)(int) 0,(LPARAM) MAKELPARAM((int) hb_parni(2),(int) hb_parni(3))));
}
HB_FUNC ( COMBOBOXGETEDITSEL )
{
HWND hWnd1;
DWORD pos;
hWnd1 = (HWND) hb_parnl (1);
pos = SendMessage((HWND) hWnd1,CB_GETEDITSEL, (WPARAM) NULL,(LPARAM) NULL);
hb_reta(2);
hb_storvni ( LOWORD(pos) , -1, 1 );
hb_storvni ( HIWORD(pos) , -1, 2 );
}
HB_FUNC ( COMBOBOXSELECTSTRING )
{
HWND hWnd1;
int n;
hWnd1 = (HWND) hb_parnl (1);
hb_retni(SendMessage((HWND) hWnd1,CB_SELECTSTRING, (WPARAM)(int) -1,(LPARAM) (LPCSTR) hb_parc(2)));
}
HB_FUNC ( COMBOBOXFINDSTRING )
{
HWND hWnd1;
int n;
hWnd1 = (HWND) hb_parnl (1);
hb_retni(SendMessage((HWND) hWnd1,CB_FINDSTRING, (WPARAM)(int) -1,(LPARAM) (LPCSTR) hb_parc(2)));
}
#pragma ENDDUMP
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
South or North HMG is worth.
...the possibilities are endless.
Re: DropDown ComboBox Programmatically
Thanks very much Masters...
Sorry for missed out your posts.
I will look into your samples...
Sorry for missed out your posts.
I will look into your samples...
Just Hmg It !
-
- Posts: 190
- Joined: Wed Jan 06, 2010 5:39 pm
Re: DropDown ComboBox Programmatically
Thanks for this sample.
But when I compile it I got this error message :
Harbour 3.2.0dev (r1312060701)
Copyright (c) 1999-2013, http://harbour-project.org/" onclick="window.open(this.href);return false;
DropDownComboBox.prg: In function 'HB_FUN_COMBOBOXSELECTSTRING':
DropDownComboBox.prg:123:12: warning: unused variable 'n' [-Wunused-variable]
DropDownComboBox.prg: In function 'HB_FUN_COMBOBOXFINDSTRING':
DropDownComboBox.prg:131:12: warning: unused variable 'n' [-Wunused-variable]
But when I compile it I got this error message :
Harbour 3.2.0dev (r1312060701)
Copyright (c) 1999-2013, http://harbour-project.org/" onclick="window.open(this.href);return false;
DropDownComboBox.prg: In function 'HB_FUN_COMBOBOXSELECTSTRING':
DropDownComboBox.prg:123:12: warning: unused variable 'n' [-Wunused-variable]
DropDownComboBox.prg: In function 'HB_FUN_COMBOBOXFINDSTRING':
DropDownComboBox.prg:131:12: warning: unused variable 'n' [-Wunused-variable]
- Rathinagiri
- Posts: 5471
- Joined: Tue Jul 29, 2008 6:30 pm
- DBs Used: MariaDB, SQLite, SQLCipher and MySQL
- Location: Sivakasi, India
- Contact:
Re: DropDown ComboBox Programmatically
You can remove that line 'int n;' and try.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
South or North HMG is worth.
...the possibilities are endless.
-
- Posts: 190
- Joined: Wed Jan 06, 2010 5:39 pm
Re: DropDown ComboBox Programmatically
I remove lines 123 and 131 and it is OK now!
Thanks
Thanks