C# 在C中从组合框中隐藏一项

C# 在C中从组合框中隐藏一项,c#,combobox,C#,Combobox,目标Vault成员集: cboDestinationVault.DataSource = Enum.GetValues(typeof(enumVaultType)) .Cast<enumVaultType>() .Select(x => new { Value = x, Description = x.ToString().Replace("_", " ") }).ToList(); cboDesti

目标Vault成员集:

cboDestinationVault.DataSource = Enum.GetValues(typeof(enumVaultType))
        .Cast<enumVaultType>()
        .Select(x => new { 
            Value = x, Description = x.ToString().Replace("_", " ") 
        }).ToList();

cboDestinationVault.DisplayMember = "Description";

cboDestinationVault.ValueMember = "Value";
我想从CBodeStationVault隐藏一个项目。

只需在Linq语句中添加Where子句即可

cboDestinationVault.DataSource = Enum.GetValues(typeof(enumVaultType))
        .Cast<enumVaultType>()
        .Where(e => e != enumVaultType.Whatever)
        .Select(x => new { 
            Value = x, Description = x.ToString().Replace("_", " ") 
        }).ToList();

如果您不想要列表中的某个内容,为什么要将其添加到列表中?谢谢sa_ddam213,对不起,我错过了上面的主要问题。实际上,我使用上面的代码只是为了加载组合框,然后我想在另一个方法中加载后隐藏一个项目
cboDestinationVault.DataSource = Enum.GetValues(typeof(enumVaultType))
        .Cast<enumVaultType>()
        .Except(new []{enumVaultType.ThisOne, enumVaultType.ThatOne})
        .Select(x => new { 
            Value = x, Description = x.ToString().Replace("_", " ") 
        }).ToList();