c# - Create enum with specific values from another enum -
i want create subset enums list system.windows.forms.keys, includes a-z, 0-9, , f keys. currently, set full list combo box on winform:
combobox1.datasource = enum.getvalues(typeof (system.windows.forms.keys));
is there fast way create subset? current workaround hardcode list of acceptable keys:
private list<keys> acceptablekeys = new list<keys> { keys.a, keys.b, keys.c, keys.d, keys.e, keys.f, keys.g, keys.h, keys.i, keys.j, keys.k, keys.l, keys.m, keys.n, keys.o, keys.p, keys.q, keys.r, keys.s, etc.... }; and use datasource.
is there better method this?
if don't want hardcode try checking int value of enum , adding them list.
var enums = enum.getvalues(typeof(keys)); list<keys> acceptablekeys = new list<keys>(); foreach (var e in enums) { int val = (int)e; //the boundaries represent a-z, 0-9, f1 - f24 respectively if ((val >= 65 && val <= 90) || (val >= 48 && val <= 59) || (val >= 112 && val <= 135)) acceptablekeys.add((keys)e); } this won't include numbers on numpad can add check if want include well.
Comments
Post a Comment