An Enhanced Combo Box Control.

CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

The ActiveX control demonstarted in this article – NCombo Control (see figure) looks like a combobox control, and has more features such as:

  • allows more than one column into control (multicolumn);
  • each column has an edit control associated. The goal of edit is the same as the standard combobox: searching, selecting. Each edit associated has more properties: enable/disable, show/hide, width. At one moment a single column can be activated.
  • allows navigating through columns by pressing TAB for next column, SHIFT+TAB for previous column.
  • each column can be resized at runtime, by dragging the column limits.
  • allows search for next matching item by pressing F3, backward searching, with SHIFT+F3, or continue search by adding more constraints.

Image of the control

The control offers the following properties, methods and events:

Properties

Type

Name

Parameters

Specification

bool

ColumnEnable

long nColumn

Get: Return TRUE if the column with index nColumn is enabled.

Set: Enable/Disable the column with index nColumn.

bool

ColumnVisible

long nColumn

Get: Return TRUE if the column with index nColumn is visibled.

Set: Show/Hide the column with index nColumn.

long

ColumnWidth

long nColumn

Get: Return the width of the column with the index nColumn.

Set: Set the width of the column with the index nColumn.

Methods:

Type

Name

Parameters

Specification

long

InsertColumn

long nColumn

CString sColumnName

long nWidth

long nJustify

bool bEnable

bool bVisible

Insert a column at nColumn position. If this position is greater than the number of columns then it will be added at the end.

  • sColumnName parameter represents the name associated to that column.
  • nWidth parameter specifies the width of the column
  • nJustify specifies the position of the text in the cell (0 – left, 1 – right, 2 –center)
  • bEnable specifies if the column is enabled or not
  • bVisible specifies if the column is visible or not

bool

DeleteColumn

long nColumn

Delete the column with the index nColumn.

Return TRUE if the column was deleted.

long

GetColumnCount

 

Return the number of columns

CString

GetColumnName

long nColumn

Return the name of the column with the index nColumn

long

InsertItem

long nItem

CString sItem

Insert an item at nItem position.

– sItem is the default value for the first column.

bool

DeleteItem

long nItem

Delete the item with the nItem index

Return TRUE if the operation has terminated successfully

bool

SetItemData

long nItem

long wData

This method associates a certain data to the item with the index nItem. This is useful, for example, when you have in the combobox a recordset and for each item with the index nItem you want the AbsolutePosition in the recordset.

Return TRUE if the operation has terminated successfully

bool

SetItemText

long nItem

long nColumn

CString sText

Put in the column nColumn of the item nItem the text sText

Return TRUE if the operation has terminated successfully

long

GetItemCount

 

Returns the number of items

long

GetItemData

long nItem

Returns the data associated to the item nItem.

CString

GetItemText

long nItem

long nColumn

Returns the text from the column nColumn of the item nItem.

Events:

Name

Parameters

Specification

ChangingItem

long nItem

This event is raised when you move through items but you don’t select anyone (the header is not changed).

ChangedItem

long nItem

This event is raised when you select an item (so when the header is changed).

ChangeColumnKey

long nColumn

This item is raised when the column key of the column nColumn is changed.

ChangeColumnContent

long nColumn

CString sColumnContent

long nType

This event is raised when you change the content of a column.

– sColumnContent represents the current content of the column with the index nColumn.

Download demo project – 187 KB

Download source – 7 KB

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read