Horizontal scroll bar in CListCtrl

Can someone tell me how to make a horizontal scrollbar in a CListCtrl, it should work like the vertical, ie. the horizontal scrollbar should only be shown if some line is too long to be shown entirely.
Who is Participating?
ClausConnect With a Mentor Commented:
The following should solve the problem. If you use tabs in the string, you
should probably use GetTabbedTextExtent instead.

CPaintDC* dc = new CPaintDC(this); // device context for painting
CRect r;
int max_width = 0;
for (i = 0; i < window->GetCount(); i ++) {
 CString s;
 window->GetText(i, s);
 CSize w = dc->GetTextExtent(s);
 if (max_width < w.cx)
  max_width = w.cx;
if (r.Width() < max_width) {
 window->ShowScrollBar(SB_HORZ, TRUE);
delete dc;

Vinayak KumbarSr Program ManagerCommented:

In Ur resourse for that ListCtrl uncheck the NoScroll option. It must work, If not try using the following functions whenever U want to display the Scrollbar

m_ctrlHexList.ShowScrollBar(SB_HORZ ,TRUE);

Here I have used some hardcoded values.

Hope it helps
Brian_HPAuthor Commented:
This solves the problem if the width of the longest string in the list box is 500 pixels (or at least known), but in my situation the widths changes from time to time, therefore I cannot just set it to 500 (or something else fixed).

Are there a way to find the longest pixel width of the string items (or just finding the width of a single string item in the list box?
Brian_HPAuthor Commented:
Adjusted points to 100
Brian_HPAuthor Commented:
The following fould at code guru is perhaps a better solution ...

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.