Programming based on the use of the dialog box list control

First, the effect of FIG.

Second, the specific steps

1. Create a new MFC application, named as 05 ListCtrl, select the application type selection dialog based Simplified Chinese, language resources, other default settings

2, through the toolbox, add a list control (List Control)

3, the right property, modify the view to Report (Report mode)

4, add a variable to a list control

Right click and select Add Variable .., modify access, add the variable name (m_list)

5, in OnInitDialog method for adding value control list using InsertColumn adding header, set the text using InsertItem and SetItemText using SetExtendedStyle method may be provided style list control

    // use the list control 
    CString STR [] = {the TEXT ( " name " ), the TEXT ( " sex " ), the TEXT ( " Age " )};
     for ( int I = 0 ; I < . 3 ; I ++ ) 
    { 
        // set header parameter index parameter 1 2 3 content alignment parameters parameter list 4 width 
        m_list.InsertColumn (I, STR [I], LVCFMT_LEFT, 100 ); 
    } 
    // set the text
     // header not the contents of the text, the index scratch
     // m_list.InsertItem (0, the TEXT ( "John Doe"));
     // to insert the data of other column Item
     //m_list.SetItemText (0, 1, TEXT ( " M")); 
    int J;
     for ( int I = 0 ; I < 10 ; I ++ ) 
    { 
        J = 0 ; 
        CString STR; 
        str.format (the TEXT ( " John Doe _ D% " ), I); 
        m_list.InsertItem (I, STR); 
        m_list.SetItemText (I, ++ J, the TEXT ( " M " )); 
        m_list.SetItemText (I, ++ J, the TEXT ( " 20 is " )); 
    } 
    // set the selected attribute entire row display grid
    m_list.SetExtendedStyle(m_list.GetExtendedStyle() | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);

 

Guess you like

Origin www.cnblogs.com/yanchaoyi/p/12667412.html