开发者

Auto resizing column widths in a CListCtrl

How can I make a CListCtrl to resize the width of its columns开发者_运维问答 automatically? Usually, when an item in the list gets too long, the back end disappears from view and the user manually has to resize the width of the corresponding column. Is there any way to do this by code?


Resizing the columns automatically is easy:

for(int i = 0;i < pListCtrl->GetHeaderCtrl()->GetItemCount();++i)
    pListCtrl->SetColumnWidth(i,LVSCW_AUTOSIZE_USEHEADER);

This will optimize the columns.


Do you have the "No Scroll" option on? By default ("No Scroll" option off), if an item got too long a scroll bar would appear.


I assume you mean a list control in report mode? Unfortunately there is no way to automatically resize columns. What you can do (what I do in some places) is calculate the width of columns as you enter items, then handle WM_SIZE and resize the columns. However this causes changes that the user made to be lost, so you may need a better algorithm like tracking if the user made any changes, if he did don't resize. It's not very nice from a UX perspective, I only use it in a select amount of circumstances where the behavior makes sense in the context of the rest of the UI.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜