Name Value Pairs in a ComboBox

后端 未结 4 1637
醉话见心
醉话见心 2021-02-01 06:42

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. ComboBo

4条回答
  •  青春惊慌失措
    2021-02-01 07:02

    The combobox items text should have contained the display text. That is the proper style. Then, use the ItemIndex property to look up the internal key values. Defeating the control's properties to contain your model code or database internal key values, is a huge violation of OOP principles.

    Let's just consider how someone is going to maintain your application in the future. You might come back to this code yourself and think, "what was I thinking?". Remember the "principle of least amazement". Use things the way they were meant to be used, and save yourself and your co-workers from pain.

提交回复
热议问题