【转】Delphi XE5中TListBox的使用方法

摘要:
转移自:http://docwiki.embarcadero.com/RADStudio/XE5/en/Mobile_Tutorial:_Using_ListBox_Components_to_Display_a_Table_View_(iOS_and_Android)MobileTutorial:使用ListBoxComponents显示表格视图(iOSandAnd
转自:http://docwiki.embarcadero.com/RADStudio/XE5/en/Mobile_Tutorial:_Using_ListBox_Components_to_Display_a_Table_View_(iOS_and_Android)
Mobile Tutorial: Using ListBox Components to Display a Table View (iOS and Android)

Go Up toMobile Tutorials: Delphi Mobile Application Development (iOS and Android)

Contents

[hide]

Using ListBox Components to Display a Table View in Mobile Applications

On the mobile platform, FireMonkey uses theFMX.ListBox.TListBoxcomponent to present aTable Viewin a mobile style, like the following ListBoxes.

Plain List

iOSAndroid (LG E-612)

IOSListBoxPlain.PNG

Android ListBoxPlain.png


Grouped List

IOSListBoxGrouped.PNG

Note:Only iOS devices support the grouped lists.

This tutorial describes the basic steps to build items for a Table View in your FireMonkey mobile applications.

Create Items on the ListBox Component

  1. SelectFile > New >FireMonkey Mobile Application- Delphi >Blank Application.
  2. Select theTListBoxcomponent in theTool Palette, and drop it on theFireMonkey Mobile Form Designer. To find TListBox, enter a few characters (such as "TListB") in theSearchbox of the Tool Palette:
    SelectTListBox.png
  3. Select theTListBoxcomponent on the Mobile Form Designer, go to theObject Inspectorand selectalClientfor theAlignproperty:
    AlClient.png
  4. On the FireMonkey Mobile Form Designer, right-click the TListBox component, and selectItems Editor:
    SelectListBoxItemsEditor.png
  5. On theItems Designer, click theAdd Itembutton several times to add several items to the ListBox:
    AddListBoxItemsOnItemsDesigner.png
  6. Close the Items Designer. Now you can find your ListBox Items on the TListBox component. For example:
    ListBoxItemsOnTListBox.png

Add a Header

You can define a Header on the TListBox component by using the following steps:

【转】Delphi XE5中TListBox的使用方法第9张
A Header for a TListBox
  1. On the FireMonkey Mobile Form Designer, right-click the TListBox component, and selectAdd Item > TListBoxHeader:
    AddTListBoxHeader.png
  2. On the Tool Palette, select theTLabelcomponent and drop it on top of theTListBoxHeadercomponent you just added:
    AddLabelOnTListBoxHeader.png
  3. In the Object Inspector, change the properties of theTLabelcomponent as follows:
PropertyValue
AlignalClient
StyleLookuptoollabel
TextAligntaCenter
Text(Text value as you want)

Add a Group Header/Footer to the List

You can define a Group Header and a Group Footer for items on TListBox as follows:

ListBoxItemsWithGroupHeaderAndFooter.png
  1. On the FireMonkey Mobile Form Designer, right-click theTListBoxcomponent, and selectItems Editor.
  2. On theItem Designer, selectTListBoxGroupHeaderfrom the drop-down list, and then selectAdd Item:
    SelectTListBoxGroupHeader.png
  3. SelectTListBoxGroupFooterfrom the drop-down list, and then selectAdd Item.
  4. SelectListBoxGroupHeader1in the list of items, and click theUpbutton several times until this item becomes the top item on the list:
    MoveListBoxGroupHeader.png
  5. Close the dialog box. Now you have a Group Header and a Group Footer on the TListBox component.

Show List Items as Separate Grouped Items

Items on a ListBox can be shown as either aPlainlist or aGroupedlist (only for iOS target platform). This choice is controlled by theGroupingKindproperty and theStyleLookupproperty, as shown in the following graphic:

Show Items as Plain ListShow Items as Grouped List
ListBoxItemsWithGroupHeaderAndFooter.pngTListBoxgsGrouped.png
gsPlain =GroupingKindProperty ValuegsGrouped =GroupingKindProperty Value
listboxstyle =StyleLookupProperty Valuetransparentlistboxstyle =StyleLookupProperty Value
Important:For iOS devices, you can specify either style for your TListBox component in the Object Inspector. For Android devices, you can specify only the plain list.

Add a Check Box or Other Accessory to a ListBox Item

Each item in a TListBox can use an Accessory such as Check Mark through theItemData.Accessoryproperty. The following picture shows the value you can assign to ItemData.Accessory and the Accessory assigned:

ValuesForItemDataAccessory.PNG

You can select the Accessory property in the Object Inspector when ListBox Item is selected in the Form Designer.

SetItemDataAccessory.png

Add an Icon to a ListBox Item

Each Item on a ListBox component can contain Bitmap data, as anIcon, through theItemData.Bitmapproperty:

SetItemDataBitmapProperty.png

You can select theBitmapproperty in the Object Inspector when the ListBoxItem is selected in the Form Designer.

Add Detail Information to an Item

You can add additional text information to each item on the ListBox component.

Specify additional text in theItemData.Detailproperty, and select the location of the Detail Text through theStyleLookupproperty, as shown in the following table:

StyleLookup propertyLook & Feel
listboxitemnodetailListBoxItemlistboxitemnodetail.PNG
listboxitembottomdetailListBoxItemlistboxitembottomdetail.PNG
listboxitemrightdetailListBoxItemlistboxitemrightdetail.PNG
listboxitemleftdetailListBoxItemlistboxitemleftdetail.PNG

Add Items to a ListBox from Your Code

To add regular items to a ListBox, you can simply call theItems.Addmethod as following code:

  ListBox1.Items.Add('Text to add');

If you want to create items other than a simple item, or control other properties, you can create an instance of the item first, and then add it to the list box.

The following code adds items to a ListBox, as shown in the picture:

iOSAndroid (LG E-612)

ListBoxItemAddedByCode.PNG

Android ListBoxItemAddedByCode.png


procedure TForm40.FormCreate(Sender: TObject);
var
  c: Char;
  i: Integer;
  Buffer: String;
  ListBoxItem : TListBoxItem;
  ListBoxGroupHeader : TListBoxGroupHeader;
begin
  ListBox1.BeginUpdate;
  for c := 'a' to 'z' do
  begin
    // Add header ('A' to 'Z') to the List
    ListBoxGroupHeader := TListBoxGroupHeader.Create(ListBox1);
    ListBoxGroupHeader.Text := UpperCase(c);
    ListBox1.AddObject(ListBoxGroupHeader);

    // Add items ('a', 'aa', 'aaa', 'b', 'bb', 'bbb', 'c', ...) to the list
    for i := 1 to 3 do
    begin
      // StringOfChar returns a string with a specified number of repeating characters.
      Buffer := StringOfChar(c, i);
      // Simply add item
      // ListBox1.Items.Add(Buffer);

      // or, you can add items by creating an instance of TListBoxItem by yourself
      ListBoxItem := TListBoxItem.Create(ListBox1);
      ListBoxItem.Text := Buffer;
      // (aNone=0, aMore=1, aDetail=2, aCheckmark=3)
      ListBoxItem.ItemData.Accessory := TListBoxItemData.TAccessory(i);
      ListBox1.AddObject(ListBoxItem);
    end;
  end;
  ListBox1.EndUpdate;
end;

Add a Search Box

You can add a search box to a ListBox. With a search box, users can easily narrow down a selection from a long list as in the following pictures:

AllStatesBeforeSearch.PNGAllStatesContainsC.PNG

  • To add a Search Box to the ListBox component, right-click theTListBoxcomponent and simply selectAdd Item > TSearchBoxfrom the context menu:

AddSearchBox.png

See Also

免责声明:文章转载自《【转】Delphi XE5中TListBox的使用方法》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇unity实现 动作游戏的连招/连击ehcache 缓存下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

随便看看

解决less 版本过高

执行npminstall--无保存加载器。安装less后,在样式中使用less时将报告错误。这是由于less loader版本过高造成的。您可以在package.json中查看less的当前版本。因此,在这种情况下,我们可以先卸载现有的less loader,然后安装less loader的较低版本npmuninstallless loader...

Qt 调用本地浏览器打开URL

单击一些Qt控件以查找本地浏览器传递的URL以打开前端。...

Cesium快速上手10-Viewer Entities组合

src=Box.html&label=Geometriesimage.pngbox就是立方体cylinder是圆锥圆柱varviewer=newCesium.Viewer;varblueBox=viewer.entities.add;varredBox=viewer.entities.add;varoutlineOnly=viewer.entitie...

buildroot使用介绍【转】

整个Buildroot由Makefile脚本和Kconfig配置文件组成。就像编译Linux内核一样,您可以编译一个完整的Linux系统软件,该软件可以通过buildroot配置和menuconfig修改直接写入机器。使用buildroot构建基于qemu的虚拟开发平台。请参阅通过buildroot+qemu构建ARM Linux虚拟开发环境。工具链--˃配...

ESXi挂载NFS共享存储

使用万兆交换机,ESXi使用NFS协议连接存储。本文介绍的是通过NFS协议挂载共享存储上的VS01卷,共享存储上已经赋予ESXi主机访问该卷的权限。...

WPF绑定功能常用属性介绍

这是实质上是System.Windows.Data.BindingMode.OneWay绑定的一种简化形式,它在源值不更改的情况下提供更好的性能。确定依赖属性绑定在默认情况下是单向还是双向的编程方法是:使用System.Windows.DependencyProperty.GetMetadata获取属性的属性元数据,然后检查System.Windows.Fr...