Solved

Limit CListCtrl to one column when in LVS_SMALLICON mode

Posted on 2012-04-12
6
811 Views
Last Modified: 2013-12-03
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.
0
Comment
Question by:sachelis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 37838536
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
 

Author Comment

by:sachelis
ID: 37838800
THanks Andy, but list boxes don't support icons (I'd need to do an owner draw which requires signifiantly more code).
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 37839099
Yeah, but I don't think what you want is possible - at least not without a lot of code either.
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 34

Assisted Solution

by:sarabande
sarabande earned 500 total points
ID: 37851034
you could use report style (LVS_REPORT) and have 1 column.

Sara
0
 

Accepted Solution

by:
sachelis earned 0 total points
ID: 37861125
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
 

Author Closing Comment

by:sachelis
ID: 37879964
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

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question