读书人

ListView 滚动条位置,该如何处理

发布时间: 2012-12-29 10:28:09 作者: rapoo

ListView 滚动条位置
如何判断ListView滚动条的位置
比如在顶端、中间或者底端

我想实现ListView展示列表的时候
滚动条位置停留在底端,每次update数据,滚动条保持在底端
滚动条不在底端,每次update数据,滚动条保持不动
[解决办法]
不用去判断滚动条的位置,只需要知道当前可视的列表部分是否把最后一条显示出来了就行,以下是简单代码,实现你需要的效果:

void __fastcall TForm1::Button1Click(TObject *Sender)
{
int nTopIndex = ListView_GetTopIndex(ListView1->Handle);
int nCountPerPage = ListView_GetCountPerPage(ListView1->Handle);

bool bScrollOnBottom = nTopIndex + nCountPerPage < ListView1->Items->Count;

Caption = String().sprintf(TEXT("滚动条%s最底端"),
bScrollOnBottom? TEXT("不在"): TEXT("在"));
}

读书人网 >C++ Builder

热点推荐