I have a class (KeywordProperties) with this code:
public class KeywordProperties { [DisplayMode("0-1,0-2,0-3,1-1,1-2,1-3,1-6,1-9,1-10,1-11,1-12,2-1,2-2,2-3,2-9,2-10,2-12,3-1,3-2,3-3,3-10,3-12,4-13,5,6")] public string Onvaan { get; set; } [DisplayMode("0-1,0-2,0-3,1-1,1-2,1-3,1-6,1-9,1-10,1-11,1-12,2-1,2-2,2-3,2-9,2-10,2-12,3-1,3-2,3-3,3-10,3-12,4-13,5,6")] public string MozooKolli { get; set; } [DisplayMode("0-10,1-10,3-10,3-12,5,6")] public string EsmeDars { get; set; } [DisplayMode("0-1,1-1,2-1,2-2,3-1,6")] public string Sokhanraan { get; set; } [DisplayMode("0-10,1-2,2-1,2-10,3-10,6")] public string Modares { get; set; } }
And I have another validation attribute:
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)] public class DisplayModeAttribute : Attribute { private readonly string mode; public DisplayModeAttribute(string mode) { this.mode = mode ?? ""; } public override bool Match(object obj) { var other = obj as DisplayModeAttribute; if (other == null) return false; if (other.mode == mode) return true; // allow for a comma-separated match, in either direction if (mode.IndexOf(',') >= 0) { string[] tokens = mode.Split(','); if (Array.IndexOf(tokens, other.mode) >= 0) return true; } else if (other.mode.IndexOf(',') >= 0) { string[] tokens = other.mode.Split(','); if (Array.IndexOf(tokens, mode) >= 0) return true; } return false; } }
I want to display properties in a propertygrid using this code:
String Code = "": KeywordProperties Kp = new KeywordProperties(); propertygrid1.SelectedObject = Kp; propertygrid1.BrowsableAttributes = new AttributeCollection(new DisplayModeAttribute(Code));
When the vlue code is "0-1" or "5" or ... (one value), I can see my properties. But, when you use "0-1,1-2" for the code, I do not see anything in my correct.
How can I see this data:
1- All properties having code 0-1 and code 1-2 :
Result: Onvaan, MozooKolli
2- All properties having code 0-1 or code 1-2 :
result: Onvaan, MozooKolli, Sokhanraan, Modares