如何(快速)在 C++ 中填充 CListCtrl (MFC)?

发布于 2024-07-26 13:32:58 字数 246 浏览 5 评论 0原文

在我的应用程序中,我有一些 CListCtrl 表。 我使用 for 循环使用数组中的数据填充/刷新它们。 在循环内部,我必须对显示值的方式进行一些调整,因此根本不可能以任何方式进行数据绑定。

真正的问题是填充表格所需的时间,因为它是逐行重新绘制的。 如果我在填充时将控件变为不可见,并在循环完成后使其再次可见,则整个方法会快得多!

现在我正在寻找一种方法来阻止控件重新绘制,直到它完全填满。 或者任何其他加快速度的方法。

in my application I have a few CListCtrl tables. I fill/refresh them with data from an array with a for-loop. Inside the loop I have to make some adjustments on how I display the values so data binding in any way is not possible at all.

The real problem is the time it takes to fill the table since it is redrawn row by row. If I turn the control invisible while it is filled and make it visible again when the loop is done the whole method is a lot faster!

Now I am looking for a way to stop the control from repainting until it is completely filled. Or any other way to speed things up.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

演多会厌 2024-08-02 13:34:21

如果您有很多记录,可能使用虚拟列表样式(LVS_OWNERDATA)更合适。 您可以在此处找到更多信息。

If you have a lot of records may be it is more appropriate to use virtual list style (LVS_OWNERDATA). You could find more information here.

如果没有你 2024-08-02 13:33:58

查看方法 SetRedraw。 在开始填充控件之前调用 SetRedraw(FALSE),在完成时调用 SetRedraw(TRUE)。

我还建议为此使用 RAII:

class CFreezeRedraw
{
public:
   CFreezeRedraw(CWnd & wnd) : m_Wnd(wnd) { m_Wnd.SetRedraw(FALSE); }
   ~CFreezeRedraw() { m_Wnd.SetRedraw(TRUE); }
private:
   CWnd & m_Wnd;
};

然后使用如下:

CFreezeRedraw freezeRedraw(myListCtrl);
//... populate control ...

如果您希望 freezeRedraw 在函数结束之前超出范围,您可以在填充列表控件的代码周围创建一个人工块。

Look into the method SetRedraw. Call SetRedraw(FALSE) before starting to fill the control, SetRedraw(TRUE) when finished.

I would also recommend using RAII for this:

class CFreezeRedraw
{
public:
   CFreezeRedraw(CWnd & wnd) : m_Wnd(wnd) { m_Wnd.SetRedraw(FALSE); }
   ~CFreezeRedraw() { m_Wnd.SetRedraw(TRUE); }
private:
   CWnd & m_Wnd;
};

Then use like:

CFreezeRedraw freezeRedraw(myListCtrl);
//... populate control ...

You can create an artificial block around the code where you populate the list control if you want freezeRedraw to go out of scope before the end of the function.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文