今天用到的,积累下来供下次使用。

一直想实现类似网页中select的那种功能,显示一个值同时对应一个隐含的值。

要用到combobox的一个方法:

virtual int __fastcall AddObject(const AnsiString S, System::TObject* AObject)

也就是说你可以将想要加载到ComboBox的对象转成一个Object。

举例说明:

 

我想要为ComboBox1加载:

Text             Value

 

苹果              apple

香蕉              banana

桃子              peach

 

则先定义一个结构体fruit

struct   fruit
{
 String   txt;
 String   vlu;
} ;

 

在加载ComboBox1的item的地方实现加载功能:

 fruit* itm = new fruit;
  itm->txt = "苹果";
  itm->vlu = "apple";
  ComboBox1->Items->AddObject(itm->txt,(TObject *)itm) ;

 

其它的item也依次添加

 

读取时只需调用

((fruit*)ComboBox1->Items->Objects[ComboBox1->ItemIndex])->vlu

bcb combobox 加载text 和value

相关文章:

  • 2022-02-11
  • 2022-12-23
  • 2021-08-13
  • 2021-12-16
  • 2022-12-23
  • 2021-11-07
  • 2021-11-07
  • 2021-06-25
猜你喜欢
  • 2021-06-07
  • 2021-08-29
  • 2022-02-24
  • 2022-03-05
  • 2022-12-23
  • 2022-12-23
  • 2021-08-24
相关资源
相似解决方案