One common control worth exploring in some more detail is the ListView, that in Delphi 2009 receives direct support for grouping. This feature requires Windows XP or Vista, with the latter providing extended features.
There are three new properties in the ListView control. The Boolean GroupView enables this new kind of display, the GroupHeaderImages refers to an ImageList containing the images for the group headers, and the
Groups property is a collection of group definitions. Each group can have a main title (Header), a related icon (TitleImage), a longer description (Subtitle), a footer line (Footer), plus some more text elements and alignment properties for headers and footer. A set of options let's you set the group as collapsible, remove the header, hide the group, and so on119.
You can see an example of grouping in a ListView in the main form of the GroupingList application, displayed below at design time:
This is the definition of the groups inside the ListView control (in DFM format), in which I've set a couple of extra descriptions that will show up only if you center the group headers:
object ListView1: TListView Groups = < item
Header = 'Arrows'
Footer = 'Footer: You can pick any of the arrows 'for the caption'
119 Some of the extra text elements of the groups are displayed only in specific cases, such as when the group header is centered (in which case several items might end up overlapping). Other features of the ListView, like the subset mode, are far from obvious to activate. I'm not sure how much of this is due to the VCL and how much to the Windows API, but looking at the SDK there is almost no documentation about some of these extended features... which probably makes wrapping them in a component some sort of guess work.
GroupID = 0
State = [IgsNormal, IgsCollapsible]
HeaderAlign = taLeftJustify
FooterAlign = taLeftJustify
Subtitle = 'Subtitle: Arrow group subtitle'
TopDescription = 'Top Descr: A group of arrows'
Titlelmage = 0
SubsetTitle = 'Subset title...' end item
Header = 'Houses'
Footer = 'Which house would you prefer?' GroupID = 1
State = [lgsNormal, lgsCollapsible] HeaderAlign = taLeftJustify FooterAlign = taLeftJustify
Subtitle = 'Houses with different colors for ' +
'the roof...' Titlelmage = 1 Extendedlmage = -1 end>
GroupHeaderlmages = ImgGroups GroupView = True end
The only code of the example is used to change the alignment of the header and footer of each group. This is the event handler of one of the three toolbar buttons:
Sender: TObject); var aGroup: TCollectionltem; begi n for aGroup in ListViewl.Groups do begi n
(aGroup as TListGroup).HeaderAlign := taRightJustify; (aGroup as TListGroup).FooterAlign := taRightJustify; end; end;
Beside grouping support, the ListView control has another unrelated new event, OnltemChecked, triggered when a user selects an item of the ListView.
Was this article helpful?
What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.