List box/check list box control of VC ++

Source: Internet
Author: User

List box/check list box control of VC ++
The ListBox window is used to list a series of texts, each of which occupies one line. To create a list window, you can use the member function:

Bool clistbox: Create (lpctstr lpsztext, DWORD dwstyle, const rect & rect, cwnd * pparentwnd, uint nid = 0 xFFFF );

Dwstyle indicates the style of the window. In addition to the commonly used style ws_child and ws_visible of the sub-window, you can specify a special style for the list control.
Lbs_multiplesel indicates that multiple rows can be selected simultaneously in the list box.
Lbs_extendedsel you can press shift/CTRL to select multiple rows
All lbs_sort rows are sorted alphabetically.

After the list box is generated, you must add or delete rows to or from the list box. You can use:

Int addstring (lpctstr lpszitem) to Add rows,
Int deletestring (uint nindex) deletes a specified row,
Int insertstring (INT nindex, lpctstr lpszitem) inserts the row into the specified position.
Void resetcontent () can delete all rows in the list box.
Call int getcount () to obtain the number of rows in the current list box.

To obtain/set the currently selected row, call int getcursel ()/INT setcursel (INT iindex ). If you specify the multi-row style, you need to call int getselcount () to obtain the number of selected rows, and then int getselitems (INT nmaxitems, lpint rgindex) obtain all the selected rows. The rgindex parameter is an array that stores the selected rows. Call int getlbtext (INT nindex, lptstr lpsztext) to obtain the string of the specified row in the list box.

In addition, you can call int findstring (INT nstartafter, lpctstr lpszitem) to find the specified character transfer position in all current rows. nstartafter indicates to start searching from that row.

Int selectstring (INT nstartafter, lpctstr lpszitem) can be used to select rows containing the specified string.

Added the cchecklistbox class in MFC 4.2, which is derived from clistbox and has all functions of clistbox. The difference is that a check box can be added before each row. Note that the lbs_ownerdrawfixed or lbs_ownerdrawvariable style must be specified during creation.

You can use void setcheckstyle (uint nstyle)/uint getcheckstyle () to set/obtain the style of the check box. For details about the check box style, refer to 4.1 button. You can use void setcheck (INT nindex, int ncheck)/INT getcheck (INT nindex) to set and obtain the check status of a row. For details about the check box status, see section 4.1 button.

At last, we will introduce several common message ing Macros in the list box:

On_lbn_dblclk double-click
On_en_errspace is generated when the input box cannot allocate memory
On_en_killfocus/on_en_setfocus is generated when the input box loses/gets the input focus
The row selected by on_lbn_selchange changes.
The preceding message ing methods are used to define the function of the prototype afx_msg void memberfxn (); and the message ing in the form of on_notification (ID, memberfxn. If the list box is used in the dialog box, class wizard automatically lists related messages and generates message ing code.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.