I need bind enum to combobox, but I need not all values
this.combobox.DataSource = Enum.GetValues(typeof(RoleUser));
public enum RoleUser { Guest = 0, Student = 1, Instructor, Administrator };
How do this?
Don't use linq
You can use theExcept
LINQ extension method for this:
Enum.GetValues (typeof(RoleUser)).Cast<RoleUser>().Except (new [] { RoleUser.Guest, RoleUser.Administrator });
With out using linq,you can put the returned value from Getvalues to an array and iterate on it to filter array then assign new created array to datasource
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.