Select the first 7 elements of an enum and display them in a Combobox using datasource

0

I have an enum that,

public enum Region {
euw,
na,
br,
lan,
ru,
oce,
tr,
jap,
}

The thing is that I would like to show the first 7 elements, or what is the same, all except the last one.

Currently with

comboBox1.DataSource = Enum.GetValues(typeof(RiotSharp.Misc.Region));

I can show the 8 elements in the comboBox, in order to show the first 7 I tried the following:

comboBox1.DataSource = Enum.GetValues(typeof(RiotSharp.Misc.Region)).Cast<RiotSharp.Misc.Region>().Where(ejemplo => 7 >= (int)ejemplo);

But he sends me the following warning:

How could I solve it?

    
asked by Omar 13.08.2018 в 09:59
source

1 answer

1

Since you're using Linq just add .ToList () to the end

Like this

comboBox1.DataSource = Enum.GetValues(typeof(Region)).Cast<Region>().Where(ejemplo => 7 >= (int)ejemplo).ToList();
    
answered by 13.08.2018 / 10:13
source