Limit CListCtrl to one column when in LVS_SMALLICON mode

I have CListCtrl that displays text and small icons while in LVS_SMALLICON mode. Occasionally a short text string will result in two list items being displayed on the same row:
Image of CListCtrl with two items on one rowI tried using CListCtrl::SetColumnWidth(), but it doesn't work when in LVS_SMALLICON mode. I tried using LVS_LIST mode and SetColumnWidth() which does fix this problem, but it then only has a horizontal scrollbar and puts information that doesn't fit in the list to the right (whereas I need one long column and a vertical scrollbar).

Thanks.
sachelisAsked:
Who is Participating?
 
sachelisConnect With a Mentor Author Commented:
I didn't save the code where I was having this problem, but after a lot of trial-and-error, I now have it displaying in one column. Sara's suggestion was good, because the LVS_REPORT style does allow you to control the number of columns, but we chose to stay with the LVS_SMALLICON style to be consistent with other lists in our app.

COurListCtrl::COurListCtrl(CWnd* pParentWnd)
{
	// Create the CListCtrl
	VERIFY( Create(LVS_AUTOARRANGE | LVS_ALIGNTOP | LVS_SMALLICON | LVS_SINGLESEL | WS_BORDER | WS_CHILD , CRect(0,0,120,300), pParentWnd, ID_OURID_LISTCONTROL ) );

	// Create a list of small icon images.
	VERIFY( (m_pImageList = new CImageList) != NULL);
	VERIFY( m_pImageList->Create(16, 16, ILC_COLOR16, 0, 1) );

	// Attach the image list to the list control.
	VERIFY( SetImageList( m_pImageList, LVSIL_SMALL ) == NULL);
}

Open in new window

0
 
AndyAinscowFreelance programmer / ConsultantCommented:
You could consider using a ListBox (not ListCtrl) instead - that only has one column.  (Except if you instruct it to use multi column that is).
0
 
sachelisAuthor Commented:
THanks Andy, but list boxes don't support icons (I'd need to do an owner draw which requires signifiantly more code).
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
AndyAinscowFreelance programmer / ConsultantCommented:
Yeah, but I don't think what you want is possible - at least not without a lot of code either.
0
 
sarabandeConnect With a Mentor Commented:
you could use report style (LVS_REPORT) and have 1 column.

Sara
0
 
sachelisAuthor Commented:
See the explantion for why this, and Sara's, solutions both work. My solution was easier to implement, because our code was already based on a small icon list.
0
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.