我现在用ListCtrl(report)显示大量数据,但要求提供这样的查找功能:
比如,当用户想找  姓名 = 张三
那么,ListCtrl就应定位在 姓名列 =  张三有二个问题:
1、要把它以不同形式显示出来,比如:换字色
2、如果不在当前页,要自动SCROOL 到指定行。
如何才能实现呢?
我想ListCtrl是不是有这样的函数:可以选定某行啊?在Windows的资源管理器中如果有好多文件,你选中某一文件后,再按一个字母‘Z’[其它也可]
便可以定位到Z为首的文件,这是如何实现的?谢谢各位啦。

解决方案 »

  1.   

    编历ListCtrl读出每个ItemText,判断是不是要找的,是的话
    m_list.SetItemState(row,LVIS_SELECTED,LVIS_SELECTED);//选中第row行
    m_list.SendMessage(WM_VSCROLL, 6, 0);//先滚到第一行
    //在滚row次
    for(int i=0;i<row;i++)
    {
       m_list.SendMessage(WM_VSCROLL, 1, 0);
    }
      

  2.   

    首先,有选中行的函数,也有搜索函数和滚动函数,至于输入Z然后自动滚动到第一个有Z的行只不过是程序在接收到键盘输入后,现搜索到满足条件的行然后滚动到并选中这一行而已。选中函数:
    SetItemState(nItem,LVIS_SELECTED,LVIS_SELECTED);滚动函数:
    BOOL EnsureVisible( int nItem, BOOL bPartialOK );搜索函数:
    int FindItem( LVFINDINFO* pFindInfo, int nStart = -1 ) const;祝你好运!
      

  3.   

    按字母Z同样道理,判断是否按键,是的话编历ListCtrl,读出每个ItemText到CString,看看CStringObg.Left(1).ToUpper()==?"Z",是的话用上面的代码先选再滚。
      

  4.   

    对,用:
    SetItemState(nItem,LVIS_SELECTED,LVIS_SELECTED);
      

  5.   

    滚动到某行可以试试wanglei888(阿笨猫) 的方法,好像是正点方法,我不知道原来还可以这样:)
      

  6.   

    对于FindItem,如果我只想找某一列的值,要如何用呢?
    能不能详细点?谢谢啦。
      

  7.   

    Virtual List Controls
    Home |  Overview |  SampleA virtual list control is a list view control that has the LVS_OWNERDATA style. This style enables the control to support an item count up to a DWORD (the default item count only extends to an int). However, the biggest advantage provided by this style is the ability to only have a subset of data items in memory at any one time. This allows the virtual list view control to lend itself for use with large databases of information, where specific methods of accessing data are already in place.Note   In addition to providing virtual list functionality in CListCtrl, MFC also provides the same functionality in theCListView class.There are some compatibility issues you should be aware of when developing virtual list controls. For more information, seeCompatibility issues: styles, states, and messages in the Platform SDK.Handling the LVN_GETDISPINFO Notification
    Virtual list controls maintains very little item information. Except for the item selection and focus information, all item information is managed by the owner of the control. Information is requested by the framework via a LVN_GETDISPINFO notification message. To provide the requested information, the owner of the virtual list control (or the control itself) must handle this notification. This can easily be done using ClassWizard. The resultant code should look something like the following example (where CMyListCtrl is the virtual list control object and the control is handling the notification):BEGIN_MESSAGE_MAP(CMyListCtrl, CListCtrl)
       //{{AFX_MSG_MAP(CMyListCtrl)
       ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnGetdispinfo)
       //}}AFX_MSG_MAP
    END_MESSAGE_MAP()In the handler for the LVN_GETDISPINFO notification message, you must check to see what type of information is being requested. The possible values are: LVIF_TEXT   The pszText member must be filled in.
    LVIF_IMAGE   The iImage member must be filled in.
    LVIF_INDENT   The iIndent member must be filled in.
    LVIF_PARAM   The lParam member must be filled in.
    LVIF_STATE   The state member must be filled in. 
    You should then supply whatever information is requested back to the framework.The following example (taken from the body of the notification handler for the list control object) demonstrates one possible method by supplying information for the text buffers and image of an item:LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
    LV_ITEM* pItem= &(pDispInfo)->item;int iItemIndx= pItem->iItem;if (pItem->mask & LVIF_TEXT) //valid text buffer?
    {
        switch(pItem->iSubItem){
            case 0: //fill in main text
                lstrcpy(pItem->pszText, 
                    m_Items[iItemIndx].m_strItemText);
                break;
            case 1: //fill in sub item 1 text
                lstrcpy(pItem->pszText,
                    m_Items[iItemIndx].m_strSubItem1Text);
                break;
            case 2: //fill in sub item 2 text
                lstrcpy(pItem->pszText,
                    m_Items[iItemIndx].m_strSubItem2Text);
                break;
        }
    }if pItem->mask & LVIF_IMAGE) //valid image?
            pItem->iImage= 
                m_Items[iItemIndx].m_iImageIndex;Caching and Virtual List Controls
    Because this type of list control is intended for large data sets, it is recommended that you cache requested item data to improve retrieval performance. The framework provides a cache-hinting mechanism to assist in optimizing the cache by sending an LVN_ODCACHEHINT notification message. However, you must use a slightly different method to handle this notification. Using ClassWizard, override the OnChildNotify function of your list control object. In the case of this example, CMyListCtrl.Inside the body of the handler, check for the LVN_ODCACHEHINT message and, if found, prepare your cache.The following example (taken from the body of the OnChildNotify function) performs this check and calls the PrepCache member function of the CMyListCtrl class.NMLVCACHEHINT* pcachehint=NULL;if (message == WM_NOTIFY)
        {
            NMHDR* phdr = (NMHDR*)lParam;        switch(phdr->code)
            {
            case LVN_ODCACHEHINT:
                pcachehint= (NMLVCACHEHINT*) phdr;
    // Load the cache with the recommended range.
                PrepCache(pcachehint->iFrom, pcachehint->iTo);
                break;
            default:
                return CListCtrl::OnChildNotify(message, wParam, lParam, pLResult);
            }
            return FALSE;
        }
        else
            return CListCtrl::OnChildNotify(message, wParam, lParam, pLResult);Notice that the notification is passed on to the base class (CListCtrl) if the message type is not LVN_ODCACHEHINT. For more information on preparing and maintaining a cache, seeCache Management in the Platform SDK.Finding Specific Items
    The LVN_ODFINDITEM notification message is sent by the virtual list control when a particular list control item needs to be found. The notification message is sent when the list view control receives quick key access or when it receives an LVM_FINDITEM message. Search information is sent in the form of an LVFINDINFO structure, which is a member of the NMLVFINDITEM structure. Handle this message by overriding the OnChildNotify function of your list control object and inside the body of the handler, check for the LVN_ODFINDITEM message. If found, perform the appropriate action.You should be prepared to search for an item that matches the information given by the list view control. You should return the index of the item if successful, or -1 if no matching item is found.