CListCtrl怎样这样显示记录?顶就给分

lk_cool 2006-05-08 04:39:11
比如说有1000条记录,界面加载时首先加载前200条,当用户拖动ListCtrl的滚动条且将要滚动到末尾时再加载200条,直到加载完毕。

就像 sql企业管理器显示表格内容的效果差不多。
...全文
315 22 打赏 收藏 转发到动态 举报
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
asewq 2006-05-09
  • 打赏
  • 举报
回复
继续up,纯属混分
c_primer_ 2006-05-09
  • 打赏
  • 举报
回复
记号!

正遇到这问题
dasiu 2006-05-09
  • 打赏
  • 举报
回复
参考 www.codeguru.com的cgridctrl类,他实现了虚拟列表功能
lqm1003 2006-05-09
  • 打赏
  • 举报
回复
学习
fine10000 2006-05-09
  • 打赏
  • 举报
回复
关注中...
学习中...
lyl_rabbit 2006-05-09
  • 打赏
  • 举报
回复
GetScrollBarCtrl 得到滚动条

GetScrollPos( ) 得到当前位置
lk_cool 2006-05-09
  • 打赏
  • 举报
回复
谢谢大家关注。
to 阿牛

我的数据也都缓存到内存中了,现在不知道怎样获得listctrl滚动条的位置。
lk_cool 2006-05-09
  • 打赏
  • 举报
回复
OK,问题解决。结贴
重写一下CListCtrl中的OnVScroll函数。点击CListCtrl控件垂直滚动条时会发送消息WM_VSCROLL,水平滚动条发送消息WM_HSCROLL,再加入WM_KEYDOWN的消息处理基本上就行了。
在OnVScroll处理函数中可以获得滚动条的位置,当前页的记录数量等....
lyl_rabbit 2006-05-08
  • 打赏
  • 举报
回复
我做一个类似的LIST,采用自绘,根据滚动条的位置刷新数据,不过数据不是取过来的,呵呵
如果要做到这样的效果,可以把取回来的数据都保存起来以备再用就可以了
会思考的草 2006-05-08
  • 打赏
  • 举报
回复
Virtual List Controls
Home | Overview | Sample

A 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.

See Also Windows Common Controls and MFC Classes
会思考的草 2006-05-08
  • 打赏
  • 举报
回复
当然是使用虚列表方式了。这种方式就是为了处理大量的数据库而产生的。MSDN中对它的介绍如下:
A 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.

easytodo 2006-05-08
  • 打赏
  • 举报
回复
关注
sunmz_wjxy 2006-05-08
  • 打赏
  • 举报
回复
关注中!!!!
mynamelj 2006-05-08
  • 打赏
  • 举报
回复
你不加载剩下的200条记录,滚动条怎可以往下拉呢?

数据量不大的情况下没必要这样做,再说你可以用其它方法嘛,比喻说分页,时间段控制...
lk_cool 2006-05-08
  • 打赏
  • 举报
回复
哦,我看过 virtual list的应用。但我不想再加按钮来处理,我想在拖动垂直滚动条的时候进行加载。
老道_ 2006-05-08
  • 打赏
  • 举报
回复
不会,学习
lixiaosan 2006-05-08
  • 打赏
  • 举报
回复
你可以响应 WM_VSCROLL,在其中GetTopIndex,得到当前显示的最大条目数,然后适时加载数据

也可以用virtual list来处理
http://www.codeguru.com/cpp/controls/listview/advanced/article.php/c4151/
striking 2006-05-08
  • 打赏
  • 举报
回复
同意楼上的.
wenkui 2006-05-08
  • 打赏
  • 举报
回复
这是virtual list的典型应用啊
看看msdn吧
应该是在listctrl加上owner data的属性吧
TOUT 2006-05-08
  • 打赏
  • 举报
回复

关注中...
学习中...
加载更多回复(2)

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧