A detailed description of the various properties in the ListBox control in MFC

Source: Internet
Author: User

The ListBox control is a space for Windows Forms, and the ListBox control displays a list of items from which the user can select one or more items.

If the total number of items exceeds the number of items that can be displayed, scroll bars are automatically added to the ListBox control. When the Multicolumn property is set to True, the list box displays items in multiple columns, and a horizontal scroll bar appears. When the Multicolumn property is set to False, the list box displays items in a single column, and a vertical scroll bar appears. When Scrollalwaysvisible is set to true, scroll bars are displayed regardless of the number of items. The SelectionMode property determines how many list items can be selected at one time.

The SelectedIndex property returns an integer value that corresponds to the first selected item in a list box. You can change the selected item programmatically by changing the SelectedIndex value in your code, and the corresponding item in the list will be highlighted on the Windows form. If no item is selected, the SelectedIndex value is-1. If the first item in the list is selected, the SelectedIndex value is 0. When multiple items are selected, the SelectedIndex value reflects the selected item that appears first in the list. The SelectedItem property is similar to SelectedIndex, but it returns the item itself, usually a string value. The Items.Count property reflects the number of items in the list, and the value of the Items.Count property is always 1 larger than the maximum possible value of SelectedIndex because the SelectedIndex is zero-based. to add or remove items from the ListBox control, use the Items.Add, Items.insert, Items.clear, or Items.remove methods. Alternatively, you can use the Items property at design time to add items to the list. Of These, the description of the four selection modes (single, multiple, extended, None) in selection: Single: Allows you to select one item at a time; multiple: Allows multiple item selection at a time; extended: Allows you to select multiple rows by pressing SHIFT or CTRL; None: The item is selected, but not highlighted, showing only the item's hand-over point (the item has a rectangular box outside it). /////////////////////////////////////////////////////////////////////////////////////

To manipulate a ListBox:

Int ListBox. AddString (LPCTSTR str): Adds a Str line of text to the first line of the ListBox, that is, at this point the nindex is 0;

Int ListBox. DeleteString (UINT NIndex): Deletes the line of text in the NIndex row of the ListBox, noting that the NIndex is starting from 0;

int ListBox. Insertstring (UINT xindex, LPCTSTR str): Inserts a Str line of text in the Nindex row of the listbox;

Int ListBox. GetCount (): Gets the total number of rows in the listbox;

Int ListBox. GetCurSel (): Gets the number of lines of text line selected in the ListBox.

Void ListBox. Resetcontent (): Clears all data in the listbox;

Int ListBox. Getcurcount (): Gets the number of rows selected in the listbox;

Int ListBox. FindString (int nstart, LPCTSTR str): Finds the lines of Str from the beginning of line Nstart;

Int ListBox. selectstring (int nstart, LPCTSTR str): Starting with line Nstart, select the line containing the STR string;

/////////////////////////////////////////////////////////////////////////////////////////

To create a response function by double-clicking on a row in the listbox:

In

Begin_message_map ()

End_message_map ()

Add a message map between the response functions, such as the function named C**DLG::ONLBNDBLCLK, and add the following code

ON_LBN_DBLCLK (IDC_LIST1,&C**DLG::ONLBNDBLCLK)

Idc_list1 is the ID of the listbox control

Then add the declaration of the function onlbndblclk () in the C**dlg.h

Finally , add the implementation code in the C**DLG::ONLBNDBLCLK () function

A detailed description of the various properties in the ListBox control in MFC

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.