gpt4 book ai didi

c# - 在 C# 中隐藏组合框中的一项

转载 作者:太空宇宙 更新时间:2023-11-03 10:59:10 25 4
gpt4 key购买 nike

目标库成员集:

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

最佳答案

只需在 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();

如果有多个你可以使用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();

关于c# - 在 C# 中隐藏组合框中的一项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18328951/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com