If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Control for owner-drawing items with 1 or 2 columns ?

Hello,

I want to show a list of graphical items in 1 or 2 columns (user selected).
I will draw the items (owner-draw).
I tried many hours today to find a solution with clistctrl.
Now, I am on the way to give up.

Re: Control for owner-drawing items with 1 or 2 columns ?

if all the images are the same size... and you just need a single text. to accompany it.

It might be easier to just use the listcontrol in the normal way (not owner draw) and put it in Iconview (LVS_ICON).
This may not be ideal if you need to handle hundreds/thousands of images though. In that case the simple way would be to use the customdraw (not ownerdraw, i.e. NM_CUSTOMDRAW) funcitonality and custom draw the items. (see http://msdn.microsoft.com/en-us/libr...v=vs.85).aspx)

Re: Control for owner-drawing items with 1 or 2 columns ?

Hello,

now, I found a solution with "small icon"-view and align=top.
I have to set the row height with the height of the images (Imagelist).
Also I can control the number of columns by setting the column width with SetColumnWidth(0,x).

Another possible solution was the report-view. There I can explicitly control the number and width of columns. But the selection of an item is to handle more difficult.

Re: Control for owner-drawing items with 1 or 2 columns ?

Hello,

I am got one more problem:
as you can imagine I use custom draw.
I want to draw my whole "grid" in the CDDS_ITEMPREPAINT-Stage.
But with
CDC* pDC=CDC::FromHandle(lpcust->nmcd.hdc);
I get a device context only for a part of the grid.
I have no access to the whole grid.

The same it is with GetItemRect: I do not get the whole grid.
Any ideas?

Re: Control for owner-drawing items with 1 or 2 columns ?

Columns will be a consequence of various other metrics which after calculations of all those metrics will end up with a number of columns that can fit on a single row.

Some of those metrics you can provide in your code (like icon spacing)
others are OS (or theme) defined (like control borders, inner padding, cell padding, cell borders)...
a couple are user manageable through the control panel (size of scrollbars, font, DPI, scaling, ...)

Your assumptions may not work:
- if the user has a different flavour of windows (classic view or themed view)
- if the user is using another theme
- if the user has selected a different DPI setting for this screen (and/or enabled XP style DPI scaling)
- if the user has selected a different systemfont
- if the user is using some of the features for improving the OS for people with disabilities.
- ...

You cannot in any reliable way control "number of columns" on a listcontrol in iconview.
The idea is that you give your control a certain width (which may get translated according to DPI settings).
The OS will calculate how many columns fit in that width
You deal with the number of columns the OS has given you.

Re: Control for owner-drawing items with 1 or 2 columns ?

The closest would be a listctrl in report view with 2 actual columns, but then you can't really select a left/right item, you select the whole row at a time.

You have a couple "weird" requirements that sort of exclude all the common controls unless you're prepared to accept the fact that your solution will only work under a specific set of assumptions. You can work around some of the inate issues with the common controls to make it work "better", but it'll Always have cases where it won't work right.

Why does it HAVE to be side by side ?
Why does it HAVE to be 2 ?
Where does that requirement come from? Just because "their old program did it that way", doesn't mean it can't be done better another way.

Often it's just better to accept the standard behaviour of the common controls and work with that, rather than trying to enforce a method into a control that wasn't designed with that method in mind.
This is especially true in that users have their expectations on the behaviour on a UI element that visually looks like something they already know. Forcing a control to do something it's not suited for may give your users a continuous sensation that "something isn't quite right".

That said, the common controls can't solve all real life problems, and sometimes you do need something that behaves "different" (the most Obvious lack in common controls is a "grid" or spreadsheet-like input). In that case, a custom control is the right way to go. Make it look sufficiently different from the common controls so users will see it's something different and not have expectations for it. (that doesn't mean it shouldn't operate in a logical/intuitive way).

THe bad part of this is that a custom control can take quite a bit of work to make.
THe good part is that there's a good chance someone has been there before you and you can find sources for the control you need (or something close enough that you can use it as a base) or premade libraries with what you need.