名称值ComboBox中的对 [英] Name Value Pairs in a ComboBox
问题描述
我相信这是一个常见的问题,但我似乎找不到一个简单的解决方案...
我想使用combobox控件用名称值对作为项目。 ComboBox使用TStrings作为它的项目,所以应该很好。
不幸的是,组合框上的绘制方法绘制Items [i],所以你在框中得到Name = Value。 / p>
我想隐藏值,所以我可以使用代码中的值,但用户看到的名称。
任何想法?
设置 Style
csOwnerDrawFixed
并写入
procedure TForm1.ComboBox1DrawItem(Control:TWinControl; Index :Integer;
Rect:TRect;状态:TOwnerDrawState);
begin
ComboBox1.Canvas.TextRect(Rect,Rect.Left,Rect.Top,ComboBox1.Items.Names [Index]);
end;
I'm convinced this must be a common problem, but I can't seem to find a simple solution...
I want to use a combobox control with name value pairs as the items. ComboBox takes TStrings as its items so that should be fine.
Unfortunately the drawing method on a combobox draws Items[i] so you get Name=Value in the box.
I'd like the value to be hidden, so I can work with the value in code, but the user sees the name.
Any Ideas?
Set Style
to csOwnerDrawFixed
and write
procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
begin
ComboBox1.Canvas.TextRect(Rect, Rect.Left, Rect.Top, ComboBox1.Items.Names[Index]);
end;
这篇关于名称值ComboBox中的对的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!