2

目标保险库成员集:

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 隐藏一项。

4

1 回答 1

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();
于 2013-08-20T07:17:23.437 回答