我如何以编程方式添加一个ListBoxItem的? [英] How can I add a ListBoxItem programmatically?

查看:335
本文介绍了我如何以编程方式添加一个ListBoxItem的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只能找到如何通过点击在组件上,创建一个 ListBoxItem的 - > 产品编辑器

I could only find how to create a ListBoxItem by clicking on the component -> Items Editor.

我们如何创建一个编程 ListBoxItem的使用 Firemonkey

How can we create programmatically a ListBoxItem using Firemonkey?

推荐答案

假设一个 ListBoxItem的是一个项目现有的的TListBox 名为 ListBox1中组件,该项目可以添加这样的:

Assuming that a ListBoxItem is an item of an existing TListBox component named ListBox1, the item can be added like this:

ListBox1.Items.Add('an item name');

替代:

var
  id: Integer;

  . . .

  ListBox1.Items.AddObject('an item name', TObject(id));

修改
注意,这种方法已被认为是仅当底层列表不排序有效

EDIT Notice that this approach has to be considered valid only if the underlying list is not sorted.

这篇关于我如何以编程方式添加一个ListBoxItem的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆