将枚举类型的值装入组合框 [英] Load values of enum type into a combobox

查看:140
本文介绍了将枚举类型的值装入组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出以下枚举:

Enum enumExample
  world
  oblivion
  holiday
End Enum



我可以将其值添加到ComboBox项目列表, p>

I can add its values to a list of ComboBox items like this:

combo.Items.Add(enumExample.holiday)
combo.Items.Add(enumExample.oblivion)
combo.Items.Add(enumExample.world)

有更短的方法吗?

推荐答案

您可以使用 Enum.GetValues 枚举然后迭代结果:

You can use Enum.GetValues to get a list of values for an enum then iterate the result:

For Each i In  [Enum].GetValues(GetType(EnumExample))
  combo.Items.Add(i)
Next

或者,如@Styxxy所述:

Or, as mentioned by @Styxxy:

combo.Items.AddRange([Enum].GetValues(GetType(EnumExample)))

这篇关于将枚举类型的值装入组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆