☆ListViewでのグループ表示
ListViewのアイテムをグループ表示させるサンプルを見つけたので試してみました。
Vistaでは更に拡張機能が使えそうです。下記のMSDNのリンクをご覧下さい。
SwissDelphiCenter.ch
...display the items in a listview control display as a group (XP)?
http://www.swissdelphicenter.ch/en/showcode.php?id=1782
MSDN
Windows と C++
Windows Vista コントロールの拡張
http://msdn2.microsoft.com/ja-jp/magazine/cc163384.aspx
uses commctrl; type TLVGROUP = record cbSize: UINT; mask: UINT; pszHeader: LPWSTR; cchHeader: Integer; pszFooter: LPWSTR; cchFooter: Integer; iGroupIdL: Integer; stateMask: UINT; state: UINT; uAlign: UINT; end; tagLVITEMA = packed record mask: UINT; iItem: Integer; iSubItem: Integer; state: UINT; stateMask: UINT; pszText: PAnsiChar; cchTextMax: Integer; iImage: Integer; lParam: lParam; iIndent: Integer; iGroupId: Integer; cColumns: UINT; puColumns: PUINT; end; TLVITEMA = tagLVITEMA; const LVM_ENABLEGROUPVIEW = LVM_FIRST + 157; LVM_INSERTGROUP = LVM_FIRST + 145; LVIF_GROUPID = $0100; LVGF_HEADER = $00000001; LVGF_ALIGN = $00000008; LVGF_GROUPID = $00000010; LVGA_HEADER_LEFT = $00000001; procedure TForm1.FormCreate(Sender: TObject); var LvGroup: TLVGROUP; LvItemA: TLVITEMA; LI: TListItem; I: Integer; S: PWideChar; begin ListView1.Items.BeginUpdate; try // 初期設定 ListView1.ViewStyle := vsReport; ListView1.Columns.Add.Caption := 'Musician'; ListView1.Columns[0].Width := 250; // 項目 LI := ListView1.Items.Add; LI.Caption := 'Deep Purple'; LI := ListView1.Items.Add; LI.Caption := 'The Beatles'; LI := ListView1.Items.Add; LI.Caption := 'Yngwie J. Malmsteen'; LI := ListView1.Items.Add; LI.Caption := 'Sarah Vaughan'; LI := ListView1.Items.Add; LI.Caption := 'Miles Davis'; SendMessage(ListView1.Handle, LVM_ENABLEGROUPVIEW, 1, 0); // グループ for I := 0 to 1 do begin FillChar(LvGroup, SizeOf(TLVGROUP), 0); LvGroup.cbSize := SizeOf(TLVGROUP); LvGroup.mask := LVGF_HEADER or LVGF_ALIGN or LVGF_GROUPID; if I = 0 then S := 'Jazz' else S := 'Rock'; LvGroup.pszHeader := S; LvGroup.cchHeader := Length(LvGroup.pszHeader); LvGroup.iGroupIdL := I; LvGroup.uAlign := LVGA_HEADER_LEFT; SendMessage(ListView1.Handle, LVM_INSERTGROUP, 0, Longint(@LvGroup)); end; // グループの設定 for I := 0 to ListView1.Items.Count - 1 do begin FillChar(LvItemA, SizeOf(TLvItemA), 0); LvItemA.mask := LVIF_GROUPID; LvItemA.iItem := I; if I < 3 then LvItemA.iGroupId := 1 else if I < 5 then LvItemA.iGroupId := 0; SendMessage(ListView1.Handle, LVM_SETITEM, 0, Longint(@LvItemA)) end; finally ListView1.Items.EndUpdate; end; end;
Vistaでは更に拡張機能が使えそうです。下記のMSDNのリンクをご覧下さい。
SwissDelphiCenter.ch
...display the items in a listview control display as a group (XP)?
http://www.swissdelphicenter.ch/en/showcode.php?id=1782
MSDN
Windows と C++
Windows Vista コントロールの拡張
http://msdn2.microsoft.com/ja-jp/magazine/cc163384.aspx
| 固定リンク