编辑:在底部更新。
希望有人能在这里帮助我,因为这使我绕过弯道!
德尔福2009
我有一个带有两个TComboxBoxEx组件的表单
我在运行时使用以下代码填充
procedure TForm1.btn1Click(Sender: TObject);
var
N: Integer;
begin
cb1.ItemsEx.Add.Caption := 'Test';
for N := 0 to 5 do
with cb1.ItemsEx.Add do
begin
Caption := 'Item ' + IntToStr(N);
Indent := 1;
end;
end;
我在设计时使用相同的数据并设置相同的属性来填充另一个。
我在运行时填充的项根本不缩进,而设计时缩进就可以了。
有任何想法吗?帮助说ident是要缩进的像素数,但是即使将indent设置为1,设计时间也要缩进一个以上的像素。
例如,在上面的代码中将缩进设置为10无效。
这是DFM中有关设计时间comobo的部分
object cb2: TComboBoxEx
Left = 184
Top = 8
Width = 145
Height = 22
ItemsEx = <
item
Caption = 'Test'
end
item
Caption = 'Item 0'
Indent = 1
end
item
Caption = 'Item 1'
Indent = 1
end
item
Caption = 'Item 2'
Indent = 1
end
item
Caption = 'Item 3'
Indent = 1
end
item
Caption = 'Item 4'
Indent = 1
end
item
Caption = 'Item 5'
Indent = 1
end>
ItemHeight = 16
TabOrder = 2
Text = 'cb1'
end
更新资料
在标题和缩进之后设置组合项的Data属性似乎可以使其正常工作。
procedure TForm1.btn1Click(Sender: TObject);
var
N: Integer;
begin
cb1.ItemsEx.Add.Caption := 'Test';
for N := 0 to 5 do
with cb1.ItemsEx.Add do
begin
Caption := 'Item ' + IntToStr(N);
Indent := 1;
Data := Pointer(N); // New Line
end;
end;
有点奇怪。
最佳答案
不太确定为什么您的代码不起作用,但是这里有一些可以解决:
for N := 0 to 5 do
cb1.ItemsEx.AddItem(intToStr(N), 0, 0, 0, DESIRED_INDENT_LEVEL, nil);
关于delphi - TComboBoxEx项目在运行时填充时不会缩进,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1312569/