如何得到ListCtrl中一项的行号?

解决方案 »

  1.   

    ListCtrl中Item的索引号就是它的行号。
    是不是已知了一项?如果楼主得到了一个LVITEM的变量的话,那就通过iItem来得到它的行号LVITEM
    Specifies or receives the attributes of a list view item. This structure has been updated to support a new mask value (LVIF_INDENT) that enables item indenting. This structure supersedes the LV_ITEM structure.typedef struct _LVITEM { 
        UINT mask; 
        int iItem; 
        int iSubItem; 
        UINT state; 
        UINT stateMask; 
        LPTSTR pszText; 
        int cchTextMax; 
        int iImage; 
        LPARAM lParam;
    #if (_WIN32_IE >= 0x0300)
        int iIndent;
    #endif
    } LVITEM, FAR *LPLVITEM; 
      

  2.   

    Messages:LBN_SELCHANGEvoid ***::OnSelchange**() 
    {
          int  i=m_***list.GetCurSel();
          ...
    }
      

  3.   

    int iSelectedItem=m_listCtrl.GetNextItem(-1,LVNI_SELECTED);
      

  4.   

    MSDN 中有CListCtrl* pListCtrl = (CListCtrl*) GetDlgItem(IDC_YOURLISTCONTROL);
    ASSERT(pListCtrl != NULL);POSITION pos = pList->GetFirstSelectedItemPosition();
    if (pos == NULL)
       TRACE0("No items were selected!\n");
    else
    {
       while (pos)
       {
          int nItem = pList->GetNextSelectedItem(pos); // 这个就是你选择的行号      TRACE1("Item %d was selected!\n", nItem);
          // you could do your own processing on nItem here
       }
    }