Mizanur Rahman Milon
Mizanur Rahman Milon

Reputation: 129

Hide one item from combobox in C#

Destination Vault Member set:

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

cboDestinationVault.DisplayMember = "Description";

cboDestinationVault.ValueMember = "Value";

I want to hide one item from cboDestinationVault.

Upvotes: 2

Views: 1725

Answers (1)

sa_ddam213
sa_ddam213

Reputation: 43636

Just add a Where clause to your Linq statement

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

if there is more than one you could use 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();

Upvotes: 2

Related Questions