目标保险柜会员集:
cboDestinationVault.DataSource = Enum.GetValues(typeof(enumVaultType))
.Cast<enumVaultType>()
.Select(x => new {
Value = x, Description = x.ToString().Replace("_", " ")
}).ToList();
cboDestinationVault.DisplayMember = "Description";
cboDestinationVault.ValueMember = "Value";
我想隐藏cboDestinationVault中的一个项目。
答案 0 :(得分:2)
只需在Where
声明
Linq
子句即可
cboDestinationVault.DataSource = Enum.GetValues(typeof(enumVaultType))
.Cast<enumVaultType>()
.Where(e => e != enumVaultType.Whatever)
.Select(x => new {
Value = x, Description = x.ToString().Replace("_", " ")
}).ToList();
如果有多个,您可以使用Except
cboDestinationVault.DataSource = Enum.GetValues(typeof(enumVaultType))
.Cast<enumVaultType>()
.Except(new []{enumVaultType.ThisOne, enumVaultType.ThatOne})
.Select(x => new {
Value = x, Description = x.ToString().Replace("_", " ")
}).ToList();