Use CtrlList control

First () function initializes the list of the class OnInitDialog:

1      // Get and set the extended style 
2      DWORD style = m_List.GetExtendedStyle ();
 . 3      m_List.SetExtendedStyle (style | LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
 . 4      // insert columns 
. 5      m_List.InsertColumn ( 0 , _T ( " No. " ), LVCFMT_LEFT , 40 );
 . 6      m_List.InsertColumn ( . 1 , _T ( " name " ), LVCFMT_LEFT, 50 );
 . 7      m_List.InsertColumn ( 2 , _T ( " Age " ), LVCFMT_LEFT, 40);
 . 8      m_List.InsertColumn ( . 3 , _T ( " sex " ), LVCFMT_LEFT, 40 );
 . 9      m_List.InsertColumn ( . 4 , _T ( " home address " ), LVCFMT_LEFT, 200 is );
 10      m_List.InsertColumn ( . 5 , _T ( " Mobile " ), LVCFMT_LEFT, 150 );
 . 11  
12 is      // insert line information 
13 is      m_List.InsertItem (m_List.GetItemCount (), _T ( " . 1 " )); // GetItemCount () returns the current line number
 14     // set the lines of text 
15      (m_List.SetItemText 0 , . 1 , _T ( " small square " ));
 16      m_List.SetItemText ( 0 , 2 , _T ( " 18 is " ));
 . 17      m_List.SetItemText ( 0 , . 3 , _T ( " F " ));
 18      m_List.SetItemText ( 0 , 4 , _T ( " Wuhan Jiangxia District fangzhen paper " ));
 19      m_List.SetItemText ( 0 , 5 , _T ( "13668875354"));
20     //再插入一行
21     m_List.InsertItem(m_List.GetItemCount(), _T("2"));
22     m_List.SetItemText(1, 1, _T("小牛"));
23     m_List.SetItemText(1, 2, _T("17"));
24     m_List.SetItemText(1, 3, _T(""));
25     m_List.SetItemText(1, 4, _T ( " Wuhan Hongshan District, Hung Chu Road " ));
 26      m_List.SetItemText ( 1 , 5 , _T ( " 13,886,189,906 " ));
1      // will select the entire line of the current line 
2      m_List.SetFocus ();
 3      m_List.SetItemState ( 1 , LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
1      // current line uncheck 
2      m_List.SetFocus ();
 3      m_List.SetItemState ( 1 , LVIS_ACTIVATING | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
 1     //遍历所有记录行
 2     int nCount = m_List.GetItemCount();
 3     for (int idx = 0; idx < nCount; ++idx)
 4     {
 5         CString szStr = m_List.GetItemText(idx, 1);
 6         szStr = m_List.GetItemText(idx, 2);
 7         szStr = m_List.GetItemText(idx, 3);
 8         szStr = m_List.GetItemText(idx, 4);
 9         szStr = m_List.GetItemText(idx, 5);
10     }
1      // iterate through all of the selected rows 
2      the POSITION POS = m_List.GetFirstSelectedItemPosition ();
 . 3      the while (POS) {
 . 4          // the line number of the obtained recording 
. 5          int IDX = m_List.GetNextSelectedItem (POS);
 . 6          CString szStr;
 . 7          szStr .Format (_T ( " % D " ), IDX);
 . 8          the MessageBox (szStr);
 . 9      }

Guess you like

Origin www.cnblogs.com/mktest123/p/12115886.html