我正在创建一个多设备FireMonkey应用程序,我想在选择TListBox项目时更改它的颜色.
如何在Rad Studio XE7中完成?
TListBox组件包含一组行(字符串).如何将此设置作为列表TList?下面的代码示例不会给出所需的结果.(Сode不编译)
MyList := TList<String>.Create(MyListBox);
MyList := TList<String>.Create(MyListBox.Items);
MyList := TList<String>.Create(MyListBox.Items.ToStringArray);
Run Code Online (Sandbox Code Playgroud)
是否可以在不使用循环的情况下执行此操作?谢谢!
我正在将 2,000 个名称加载到 FMX TListBox 中,但花费的时间太长(例如 35 秒或更长)。
这是测试代码:
procedure TDocWindow.DEBUGAddLotsOfStringsToList;
var
theTimeAtStart: Integer;
J: Integer;
begin
ListBox1.Clear;
theTimeAtStart := TThread.GetTickCount;
for J := 1 to 2200 do
begin
ListBox1.Items.Add(j.toString);
end;
ShowMessage('There were ' + J.ToString + ' strings added to the list in ' + (TThread.GetTickCount - theTimeAtStart).ToString + ' milliseconds.');
end;
Run Code Online (Sandbox Code Playgroud)
TListBox 是否有什么东西使得它对于几千个字符串来说太慢了?
我试图在添加/编辑条目后触发对TListBox控件中的项目进行排序。
我看到有一个我已设置为true 的Sorted属性,但是,每当我对内容进行更改时,它都不会对ListBox进行动态排序。似乎没有任何可用的排序过程或函数,并且调用Update或Refresh效果不理想。
我已经到了考虑将ListBox的内容拉入TStringList对象,对其进行排序然后将所有内容再次放回ListBox的阶段。不过,这似乎有些疯狂,我肯定会忽略一些更好的方法。
这是更改现有项目的示例:
myListBox.Items[myIndex] := newString; // Update Text
myListBox.Items.Objects[myIndex] := TObject(my_object); // Update associated object
Run Code Online (Sandbox Code Playgroud)
我希望控件进行更新以使内容按字母顺序排序,但事实并非如此。
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
begin
inherited;
TListBox(Control).Canvas.FillRect(Rect);
TListBox(Control).Canvas.TextOut(Rect.Left+5, Rect.Top+8, TListBox(Control).Items[Index]);
if odSelected in State then
begin
Button.Left:=Rect.Right-80;
Button.Top:=Rect.Top+4;
Button.Visible:=true;
Button.Invalidate;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ListBox1.DoubleBuffered:=true;
ListBox1.ItemHeight:=30;
ListBox1.Style:=lbOwnerDrawFixed;
Button:=TButton.Create(ListBox1);
Button.Parent:=ListBox1;
Button.DoubleBuffered:=true;
Button.Visible:=false;
Button.Width:=50;
Button.Height:=20;
Button.Caption:='BTN';
end;
Run Code Online (Sandbox Code Playgroud)


只有在使用ScrollBar或向我的ListBox发送WM_VSCROLL消息时才会出现重绘问题.当我通过使用键盘箭头或鼠标点击更改选择时,通常都会绘制.当通过滚动显示所选项目而不留下可见区域时,问题也不存在.
我认为Button.Top属性在DrawItem调用之前仍然具有旧值,并且稍后更改(例如为-30px).
我正在尝试使用编辑框过滤 Delphi 中的列表框,但它不起作用。这是我基于编辑框的 OnChange 事件的代码。
procedure TReportDlgForm.FilterEditOnChange(Sender: TObject);
var
I: Integer;
begin
ListBox1.Items.BeginUpdate;
try
for I := 0 to ListBox1.Items.Count - 1 do
ListBox1.Selected[I] := ContainsText(ListBox1.Items[I], FilterEdit.Text);
finally
ListBox1.Items.EndUpdate;
end;
end;
Run Code Online (Sandbox Code Playgroud)
我希望当我在编辑框中键入内容时,列表框项目将被过滤。