我想根据双击列表某项的函数OnDblclkList(NMHDR* pNMHDR, LRESULT* pResult)来控制列表内容。    我的问题是:如何获得当前选择项Current Item,如何获得当前列表的列的数目?如何取出每项的内容?
    希望高手帮忙,谢谢

解决方案 »

  1.   

    GetItemCount Retrieves the number of items in a list view control. GetItemData Retrieves the application-specific value associated with an item. GetItemPosition 
      

  2.   

    如何获得当前选择项Current Item?
    GetSelectedCount()   Retrieves the number of selected items in the list view control. 
    如何获得当前列表的列的数目?
    GetItemCount() Retrieves the number of items in a list view control. 
    如何取出每项的内容?
    GetItemText() Retrieves the text of a list view item or subitem. 
      

  3.   

    GetItemCount() 不是获得行的总数吗?我是这样做的 int Item;
             CCenterMngDlg theDlg;
    Item=m_ctrllist.GetHotItem();
    m_ctrllist.SetHotItem(0);
    int count=theDlg.pFields->Count;
    CString strtemp;
    for(int i=0;i<count;i++)
    {
    strtemp+=m_ctrllist.GetItemText(Item,i);
    }
    AfxMessageBox(strtemp);
    结果是Item得到-1值,为什么这样呢?
      

  4.   

    jennyvenus(JennyVenus)恭喜你升为两星
      

  5.   

    结果是-1就证明当前没有处于鼠标前的ITEM,更多是你没有设置hot tracking 有效吧
      

  6.   

    POSITION pos = this->GetFirstSelectedItemPosition();
    if (pos == NULL)
    TRACE0("No items were selected!\n");
    else
    {
    while (pos)
    {
    int nItem = this->GetNextSelectedItem(pos);
    }
      

  7.   

    int nCount = GetItemCount();
      

  8.   

    CString cs;
    GetItemText(0,0,cs);
      

  9.   

    谢谢各位的解答,我是这样解决的。可是有一个问题没解决,for(int i=0;i<25;i++)中,25是一个常数,我想用count动态指定,不知道怎么做。按hhuangchunlin(林之韵) 朋友的说法应该用GetItemCount(),我马上去试,要能解决那真太感谢你们了。void tabdlg1::OnDblclkList(NMHDR* pNMHDR, LRESULT* pResult) 
    {
    // TODO: Add your control notification handler code here]
    POSITION pos = m_ctrllist.GetFirstSelectedItemPosition();
    if(!pos)
    {
    AfxMessageBox("hi,将弹出新建用户对话框");
    }
    else
    {
    AfxMessageBox("将弹出修改用户对话框");
    int item=m_ctrllist.GetNextItem(-1,LVNI_SELECTED);
    CString strtemp[25];
    int j=0;
    for(int i=0;i<25;i++)
    {
    strtemp[i]=m_ctrllist.GetItemText(item,i);
    if(strtemp[i]!="")
    {
    value[j]=strtemp[i];
    j++;
    }
    }
    }
    *pResult = 0;
    }
      

  10.   

    FT~GetItemCount()得到的是行数,我希望能得到列数,就是说希望能有一个GetColumnCount()函数,怎么获得?
      

  11.   

    GetSelectedCount()   是获得选择了多少个Item,并不是当前鼠标选中的单个Item。我看CListCtrl似乎没有提供类似CListBox.GetCurSel()这样的函数。
    所以前面有些人的解答是错误的。
      

  12.   

    to xjtt2000(沧海一笑) 依你之见,怎么解决这么问题呢?现在最让我头疼的是怎么取得列的数目呢?
      

  13.   

    是不是你在Message问我这个问题,我已经RE你了。可以达到你的要求。
      

  14.   

    哦,我这就过去看看,谢谢你不知你是否有能再帮我一个忙,回答http://expert.csdn.net/Expert/topic/1188/1188858.xml?temp=.2262689
    今天又新遇到的问题
      

  15.   

    十分感谢你,可以看得出来我代码里的
    POSITION pos = m_ctrllist.GetFirstSelectedItemPosition();
    if(!pos)
    {}
             else
             {}
    也是用你的代码。
    根据你在MESSAGE里的方法,我已经解决了COUNT问题。再次表示感谢!
      

  16.   

    另外我的http://expert.csdn.net/Expert/topic/1188/1188858.xml?temp=.2262689帖子也终于被我弄清楚了,谢谢各位的帮忙!