Page 1 of 1

DropDown ComboBox Programmatically

Posted: Wed Apr 30, 2014 5:33 am
by hmgchang
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

Re: DropDown ComboBox Programmatically

Posted: Wed Apr 30, 2014 3:06 pm
by Javier Tovar
Hola hmgChang,

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.
Ej.:

Form_1.Combo_1.AddItem("UNO")
Form_1.Combo_1.AddItem("DOS")
Form_1.Combo_1.AddItem("TRES")...

Saludos

Re: DropDown ComboBox Programmatically

Posted: Wed Apr 30, 2014 4:58 pm
by Rathinagiri
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
    




Re: DropDown ComboBox Programmatically

Posted: Wed Apr 30, 2014 6:12 pm
by esgici
Rathinagiri wrote:Yes. Just see this small sample.
...
Impressive :!:

May be a way to make this little and powerful function a method ?

Something like

Code: Select all

myForm.myComboSBox.ForceDropDown() 
Best regards

Re: DropDown ComboBox Programmatically

Posted: Thu May 01, 2014 12:05 am
by Javier Tovar
Hola Rathinagiri,

Bonito ejemplo! :D :D :D

Saludos

Re: DropDown ComboBox Programmatically

Posted: Thu May 01, 2014 4:46 am
by Rathinagiri
Please see this sample which I had made two years ago. :)

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
It requires a 'Countires.lst' file which shall contain the list of countries. You can use this.
Afghanistan
Albania
Algeria
Andorra
Angola
Argentina
Armenia
Australia
Austria
Azerbaijan
Bahamas
Bahrain
Bangladesh
Barbados
Belarus
Belgium
Belize
Benin
Bhutan
Bolivia
Bosnia-Herzegovina
Botswana
Brazil
Britain
Brunei
Bulgaria
Burkina
Burma (Myanmar)
Burundi
Cambodia
Cameroon
Canada
Cape Verde Islands
Chad
Chile
China
Colombia
Congo
Costa Rica
Croatia
Cuba
Cyprus
Czech Republic
Denmark
Djibouti
Dominica
Dominican Republic
Ecuador
Egypt
El Salvador
England
Eritrea
Estonia
Ethiopia
Fiji
Finland
France
Gabon
Gambia, the
Georgia
Germany
Ghana
Greece
Grenada
Guatemala
Guinea
Guyana
Haiti
Holland (Netherlands)
Honduras
Hungary
Iceland
India
Indonesia
Iran
Iraq
Ireland
Israel
Italy
Jamaica
Japan
Jordan
Kazakhstan
Kenya
Kuwait
Laos
Latvia
Lebanon
Liberia
Libya
Liechtenstein
Lithuania
Luxembourg
Macedonia
Madagascar
Malawi
Malaysia
Maldives
Mali
Malta
Mauritania
Mauritius
Mexico
Moldova
Monaco
Mongolia
Montenegro
Morocco
Mozambique
Myanmar ( Burma )
Namibia
Nepal
Netherlands (Holland)
New Zealand
Nicaragua
Niger
Nigeria
North Korea
Norway
Oman
Pakistan
Panama
Papua New Guinea
Paraguay
Peru
Philippines
Poland
Portugal
Qatar
Romania
Russia
Rwanda
Saudi Arabia
Scotland
Senegal
Serbia
Seychelles
Sierra Leone
Singapore
Slovakia
Slovenia
Solomon Islands
Somalia
South Africa
South Korea
Spain
Sri Lanka
Sudan
Suriname
Swaziland
Sweden
Switzerland
Syria
Taiwan
Tajikistan
Tanzania
Thailand
Togo
Trinidad and Tobago
Tunisia
Turkey
Turkmenistan
Tuvali
Uganda
Ukraine
United Arab Emirates
United Kingdom
United States of America
Uruguay
Uzbekistan
Vanuata
Vatican City
Venezuela
Vietnam
Wales
Western Samoa
Yemen
Yugoslavia
Zaire
Zambia
Zimbabwe

Re: DropDown ComboBox Programmatically

Posted: Fri May 02, 2014 1:48 am
by hmgchang
Thanks very much Masters...
Sorry for missed out your posts. :)
I will look into your samples...

Re: DropDown ComboBox Programmatically

Posted: Sun May 04, 2014 8:57 am
by chrisjx2002
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]

Re: DropDown ComboBox Programmatically

Posted: Sun May 04, 2014 12:49 pm
by Rathinagiri
You can remove that line 'int n;' and try.

Re: DropDown ComboBox Programmatically

Posted: Sun May 04, 2014 1:44 pm
by chrisjx2002
I remove lines 123 and 131 and it is OK now!

Thanks