从数据库里面检索出10几万条记录,需要显示在程序上
各位有没有什么好建议啊
我用最普通的List Ctrl做的
ListCtrl每次插入数据都要刷新一次吗,怎么那么闪啊
而且速度很慢
我是在线程里得到数据,然后发消息给对话框
在将得到的数据(10多万)条插入到ListCtrl里
根本就显示不出来啊
数据少的时候(不到100)条,ListCtrl显示起来也是特别闪
我想实现这种效果
数据一条一条的插入,光标滑块不随着插入而往下拉,这样在表面上看,就已经有那么多数据了,后台再不停的往ListCtrl后面插入数据,对前台对话框没什么影响
高手帮帮忙啊,郁闷死了~~~~~~

解决方案 »

  1.   

    // Updating a control or window with large amounts of data may cause
    // flicker. In such cases it may be better to turn off drawing.//...  //m_list is a member of type CListCtrl
      m_List.SetRedraw(FALSE);  // Turn drawing off regardless of list mode.//...
    // Update control
    //...  m_List.SetRedraw(TRUE);  // Turn drawing back on and update the window.  // Invalidate the entire control, force painting.
      m_List.Invalidate();
      m_List.UpdateWindow();
      

  2.   

    可以参考:
    http://community.csdn.net/Expert/FAQ/FAQ_Index.asp?id=190778
      

  3.   

    在csdn上有个帖子,名字叫《ADO+ListCtrl显示数据库记录(100000条以上)求助!急!》
     可能对你有帮助的,我把网页保存下来了,但是连接你可以自己搜一下吧
      

  4.   

    这个最合适了,来自MSDN: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.
      

  5.   

    m_listCtrl.SetRedraw(FALSE);
    ...
    m_listCtrl.SetRedraw(TRUE);
      

  6.   

    参见
    http://community.csdn.net/Expert/topic/4129/4129364.xml?temp=.5886347
      

  7.   

    是不是每次插入的时候,ListCtrl都自己redrew一下,所以特别慢啊
      

  8.   

    我想这样也许会解决问题,每插入相当数量的item之后再刷新
    但是刷新之前,如果停止刷新就要setredraw(0);
    这样以前查询的结果也看不见了
    怎么才能使ListCtrl保持现有已刷新的显示结果,停止刷新呢,
    这样就可以浏览已经有的数据,当再增加相当的数据时,刷新一次,视觉效果应该有改善吧
      

  9.   

    到www.codeproject.com中去看看,可以找到你所要的东西,如楼主所说,这东西就是虚列表
    我用这个东西一次加入二万多条记录,时间在四秒左右
      

  10.   

    如果你不想用虚列表,可以在查入数据之前先锁定ListCtrl窗口,LockWindowUpdate(),查入完成之后用
    UnlockWindowUpdate();
    UpdateWindow();