clistbox 子项目标题已经获得,如何根据子项目标题 获取索引号?

解决方案 »

  1.   

    ?是这个意思吗?:int GetIdxByItemName(CString strCheck)
    {
    //遍历listbox各项
    CString strItem;
    for (int i = 0; i < m_lstbox.GetCount(); ++i)
    {
    m_lstbox.GetText(i, strItem);
    if (strItem.Compare(strCheck) == 0)
    return i;
    } return -1;
    }注意项目字串重复的情况要不要处理~~
      

  2.   


    int    GetIdxByItemName(CString strCheck)
    {
        //遍历listbox各项
        CString strItem;
        int j = m_lstbox.GetCount(); 
        for (int i = 0; i < j; ++i)
        {
            m_lstbox.GetText(i, strItem);
            if ( strItem=="你的字符串")
            {
                return i;
             }
        }
        return -1;
    }
      

  3.   

    CListBox::FindString 
    int FindString( int nStartAfter, LPCTSTR lpszItem ) const;
      

  4.   


    MFC有提供现成的函数~~~FindString