Comboboxes

From Team Developer SqlWindows Wiki
Revision as of 11:21, 29 October 2013 by DaveRabelink (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

ComboBox


Contents


Pointer2.png How to set the dropdown list width Pointer.png

For default, the width of the dropdown list is the same as the combobox width.
You can change the width programatically.

To do this you will have to send a message to the Combobox and supply a new width in pixels.
Also the current width in pixels can be determined.
First you have to declare these constants

Number: CB_GETDROPPEDWIDTH   = 0x015F
Number: CB_SETDROPPEDWIDTH   = 0x0160

(More information on CB_GETDROPPEDWIDTH and CB_SETDROPPEDWIDTH)

The next piece of code sets the width of combobox cmbSample to 100 pixels

Call SalSendMsg( cmbSample, CB_SETDROPPEDWIDTH, 100, 0 )

The next piece of code gets the current width of combobox cmbSample in pixels

Set nWidth = SalSendMsg( cmbSample, CB_GETDROPPEDWIDTH, 0, 0 )

The next piece of code doubles the width of combobox cmbSample

Call SalSendMsg( cmbSample, CB_SETDROPPEDWIDTH, SalSendMsg( cmbSample, CB_GETDROPPEDWIDTH, 0, 0 )*2, 0 )


Pointer2.png How to programatically open the dropdown list Pointer.png

Open (or close) the dropdown list of a combobox using

Call VisListSetDropDownState( hWndList, bState )

! bState = TRUE to open
! bState = FALSE to close

Pointer2.png How to get the handles of the edit and list parts of a combobox Pointer.png

TODO -> CB_GETCOMBOBOXINFO.

Pointer2.png How to set the vertical size of the dropdown list programatically Pointer.png

TODO -> CB_SETMINVISIBLE.

Pointer2.png How to set the height of the edit portion and list entries programatically Pointer.png

The height of the edit control portion and the dropdown list entries can be changed.

To do this you will have to send a message to the Combobox and supply a new height in pixels.
Also the current height in pixels can be determined.
First you have to declare these constants

Number: CB_SETITEMHEIGHT     = 0x0153
Number: CB_GETITEMHEIGHT     = 0x0154

( More information on CB_SETITEMHEIGHT and CB_GETITEMHEIGHT )

To set the height of the edit control portion of combobox cmbSample to 30 pixels

Call SalSendMsg( cmbSample, CB_SETITEMHEIGHT , -1, 30 )

To set the height of the dropdown list entries of combobox cmbSample to 30 pixels

Call SalSendMsg( cmbSample, CB_SETITEMHEIGHT , 0, 30 )

To get the current height of the edit control portion and items of combobox cmbSample in pixels

Set nEditHeight = SalSendMsg( cmbSample, CB_GETITEMHEIGHT , -1, 0)
Set nItemHeight = SalSendMsg( cmbSample, CB_GETITEMHEIGHT , 0, 0)


Pointer2.png How to prevent combobox dropdown Pointer.png

To prevent the combobox list popping up (dropdown) when clicking on the dropdown button, here is a solution.
The edit part of the combobox is unaffected.

First declare these constants

Number: WM_NCHITTEST   = 0x84
!
Number: HTNOWHERE      = 0


Now, trap WM_NCHITTEST on the combobox.

Combo Box: cmb1
    Message Actions
        On WM_NCHITTEST
            Return HTNOWHERE


Here you can download a sample:
Down.png WIKI_PreventComboboxDropdown.zip