如何选取CListView(report格式) 中的一个值?

解决方案 »

  1.   

    CListCtrl* pListCtrl = (CListCtrl*) GetDlgItem(IDC_VIEW_LIST);
    ASSERT(pListCtrl != NULL);
    POSITION pos = m_listView.GetFirstSelectedItemPosition();
    if (pos == NULL)
    TRACE0("No items were selected!\n");
    else
    {
    int nn;
    while (pos)
    {
    int nItem = m_listView.GetNextSelectedItem(pos);
    TRACE1("Item %d was selected!\n", nItem);
    CString cc;
    cc.Format("%d", nItem);
    //AfxMessageBox(cc);
    nn=nItem;
    }
    CString str = m_listView.GetItemText(nn, 0);
    int length=str.GetLength();
    length=length-4;
    CString strTmp = str.Left(length);
    CString strTmp1=strTmp+_T(".txt");
    CString strTmp2=strTmp+_T(".doc");
    //AfxMessageBox(strTmp1);
    //AfxMessageBox(strTmp2);
    // }
    CString DBtext;
    for(int j=0;((DBtext!=strTmp1) && (DBtext!=strTmp2));j++)
    {DBtext=m_listView.GetItemText(j, 0);}
    /* int j=0;
    CString DBtext=m_listView.GetItemText(j, 0); do {
    j++;
    DBtext=m_listView.GetItemText(j, 0);
    }
    while ((DBtext!=strTmp1) && (DBtext!=strTmp2));
    */ //AfxMessageBox(DBtext);
    }
      

  2.   

    CListCtrl* pListCtrl = (CListCtrl*) GetDlgItem(IDC_VIEW_LIST);
    ASSERT(pListCtrl != NULL);
    POSITION pos = m_listView.GetFirstSelectedItemPosition();
    if (pos == NULL)
    TRACE0("No items were selected!\n");
    else
    {
    int nn;
    while (pos)
    {
    int nItem = m_listView.GetNextSelectedItem(pos);
    TRACE1("Item %d was selected!\n", nItem);
    CString cc;
    cc.Format("%d", nItem);
    //AfxMessageBox(cc);
    nn=nItem;
    }
    CString str = m_listView.GetItemText(nn, 0);
    int length=str.GetLength();
    length=length-4;
    CString strTmp = str.Left(length);
    CString strTmp1=strTmp+_T(".txt");
    CString strTmp2=strTmp+_T(".doc");
    //AfxMessageBox(strTmp1);
    //AfxMessageBox(strTmp2);
    // }
    CString DBtext;
    for(int j=0;((DBtext!=strTmp1) && (DBtext!=strTmp2));j++)
    {DBtext=m_listView.GetItemText(j, 0);}
    /* int j=0;
    CString DBtext=m_listView.GetItemText(j, 0); do {
    j++;
    DBtext=m_listView.GetItemText(j, 0);
    }
    while ((DBtext!=strTmp1) && (DBtext!=strTmp2));
    */ //AfxMessageBox(DBtext);
    }

      

  3.   

    CListCtrl &listctrl = yourlistview.GetListCtrl();
    要得到index为nIdx的text:
    CString strText = listctrl.GetItemText(nIdx, 0);
      

  4.   

    或者这样说,report方式下,要得到nRow行,nCol列的Text(如果这个cell中是text):
    CString strText = listctrl.GetItemText(nRow, nCol);