views:

234

answers:

3

Hi,

Is there a way to resize the listcontrol automatically? Usually when the item gets too long the back end disappears from view and the user manually has to resize the width of the column. Is there anyway to do this by the code?

Thank You!!

+1  A: 

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.

djeidot
+1  A: 

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.

Roel
Yes that is exactly what I meant. Thanks for the reply, if I cant get a suitable algo, I'll just handle OnSize() for resizing manually and ask the reader to resize the window.
Isuru
+1  A: 

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.

dwo
Hey, I tried it and it seems to work well :) :) Thanks a lot for the reply dwo :D
Isuru
A small question dwo, I have never heard about HeaderControl. What exactly is it???Thanks a lot!!!
Isuru
The header control is the upper part of the list control with the column titles in it.
dwo