Delphi XE2 之 FireMonkey 入门(41) - 控件基础: TListBox


TScrollBox -> TCustomListBox -> TListBox; 其元素项是 TListBoxItem 类型.

TListBox 的功能在 TCustomListBox 里就完成了.

值得注意的变化是:
1、复选框(相关属性: ShowCheckboxes、TListBoxItem.IsChecked)
2、交替背景(通过继承还可以调整交替的背景色)
3、TListBoxItem 可调整大小、容纳其它对象.

{ TCustomListBox }
public
  constructor Create(...); override;          //
  destructor Destroy; override;               //
  procedure Assign(...); override;            //
  procedure Clear; virtual;                   //清空
  function DragChange(...): Boolean; dynamic; //调用 OnDragChange 事件
  procedure SelectAll;                        //全选
  procedure ClearSelection;                   //取消选择
  procedure SelectRange(...);                 //选择指定范围
  function ItemByPoint(...): TListBoxItem;    //获取指定位置的项
  function ItemByIndex(...): TListBoxItem;    //获取指定序号的项
  procedure Exchange(...);                    //交换项
  procedure AddObject(...); override;         //添加项
  procedure RemoveObject(...); override;      //删除项
  procedure Sort(...); override;              //排序
  property Count: Integer ...;                //项总数
  property Selected: TListBoxItem ...;        //当前选择的项
  property Items: TStrings ...;               //元素文本的集合
  property ListItems[Index: Integer]: TListBoxItem ...; //根据索引获取项
  property ItemIndex: Integer ...;                      //索引
end;

{ TListBox }
published
  property StyleLookup;              //
  property AllowDrag;                //是否允许拖放
  property CanFocus;                 //
  property DisableFocusEffect;       //
  property TabOrder;                 //
  property AlternatingRowBackground; //是否使用交替背景
  property Columns;                  //列数; 默认 1
  property HideSelectionUnfocused;   //在失去焦点时是否隐藏选择
  property Items;                    //
  property ItemIndex;                //
  property ItemWidth;                //项宽
  property ItemHeight;               //项高
  property ListStyle;                //列表样式; TListStyle = (lsVertical, lsHorizontal);
  property MultiSelect;              //是否允许多选; 为 True 时, 配合 Ctrl 键多选
  property Sorted;                   //
  property ShowCheckboxes;           //是否显示复选框; 默认 False
  property BindingSource;            //绑定源
  property OnChange;                 //有变化时
  property OnChangeCheck;            //调整复选框时
  property OnCompare;                //排序比较时
  property OnDragChange;             //拖放项时
end;

{ TListBoxItem }
public
  constructor Create(...); override; //
  property Data: TObject ...;        //
  property Index: Integer ...;       //
published
  property IsChecked: Boolean ...;   //复选值
  property IsSelected: Boolean ...;  //
  property AutoTranslate ...;        //
  property Font;                     //
  property StyleLookup;              //
  property Text;                     //
  property TextAlign ...;            //
  property WordWrap;                 //
end;


测试:

procedure TForm1.FormCreate(Sender: TObject);
var
  i: Integer;
begin
  ListBox1.Align := TAlignLayout.alLeft;
  ListBox1.ShowCheckboxes := True;
  ListBox1.AlternatingRowBackground := True;
  for i := 0 to 9 do
  begin
    ListBox1.Items.Add('Itme' + IntToStr(i));
    ListBox1.ListItems[i].IsChecked := Odd(i);
  end;
end;

转载于:https://my.oschina.net/hermer/blog/320961

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ModernListView (Berlin, Tokyo [with fix], Rio) 很好的Delphi Firemonkey控件,可用作Android、iOS、MacOS、Windows开发,比Delphi自带的listview更好用、功能更强大! ListView1.SetColorItemSelected(TAlphaColorRec.Orangered); ListView1.SetColorItemFill(TAlphaColorRec.Whitesmoke); ListView1.SetColorItemFillAlt(TAlphaColorRec.Lightgrey); ListView1.SetColorBackground(TAlphaColorRec.Whitesmoke); ListView1.SetColorItemSeparator(TAlphaColorRec.Red); ListView1.SetColorText(TAlphaColorRec.Darkmagenta); ListView1.SetColorTextSelected(TAlphaColorRec.Blueviolet); ListView1.SetColorTextDetail(TAlphaColorRec.Darksalmon); ListView1.SetColorHeader(TAlphaColorRec.Crimson); ListView1.SetColorTextHeader(TAlphaColorRec.Whitesmoke); ListView1.SetColorTextHeaderShadow(TAlphaColorRec.grey); ListView1.SetColorPullRefresh(TAlphaColorRec.Lime); ListView1.SetColorPullRefreshIndicator(TAlphaColorRec.Limegreen); ListView1.SetColorStretchGlow(TAlphaColorRec.Limegreen); Style for ListView Columns Mode ListView1.ShowScrollBar - hide/show scrollbar ListView1.ItemsClearTrue - correct delete items ListView1.OffsetTop - indent of the first element ListView1.OffsetBottom - indent of the last element ListView1.getFirstVisibleItemIndex - first visible ItemIndex ListView1.getVisibleCount - amount of visible items ListView1.getLastVisibleItemindex - first visible ItemIndex + amount of visible items ListView1.SeparatorLeftOffset - indent for separator line ListView1.SeparatorRightOffset - indent for separator line ListView1.EnableTouchAnimation - enable/disable touch animation

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值