I found this thread but this is more than a year old and I'm using the latest version Has anything changed to fix the issue? Is there another attribute I should be using to get the desire effect? Or do I have to use reflection, test for Browsable attribute and set AllowHiding on related field? Seems like a lot of work and I got tons of grids in my app that will have to run that code. Would just be easier if there was a setting to hide both from grid and field window. That way I can use style to set the property on all grids once. Or default it that way.
http://es.infragistics.com/community/forums/p/56331/288556.aspx#288556
HI,
Please let me know if you need further assistance regarding this issue?
Sincerely,
Matt
Developer Support Engineer
Here is what I came up with quickly. Note I programmed this to work with my classes. For example all my grids dataSources inherts a class which inherts BindingList<T>.
/// <summary> /// Sets AllowHiding = "Never" to properties that have the Browsable attribute set to false /// </summary> /// <param name="grid"></param> public static void SetupAllowHiding(XamDataGrid grid) { if (grid == null) throw new ArgumentNullException("grid", "Parameter grid must not be null"); if (grid.DataSource == null) throw new ArgumentNullException("grid.DataSource", "DataSource must be assigned");
object o = grid.DataSource; Type t = o.GetType().BaseType.GetGenericArguments()[0]; //Datasource usally derives from dbObjBaseCollection<T>. Get T the generic Argument. Field field;
foreach (PropertyInfo pi in t.GetProperties(BindingFlags.Instance | BindingFlags.Public)) { field = null;
try { field = grid.FieldLayouts[0].Fields[pi.Name]; } catch (Exception) { //throw; }
if (field != null) { System.ComponentModel.BrowsableAttribute[] attrbs = pi.GetCustomAttributes(typeof(System.ComponentModel.BrowsableAttribute), true) as System.ComponentModel.BrowsableAttribute[]; if (attrbs != null && attrbs.Length > 0) { if (!attrbs[0].Browsable) field.Settings.AllowHiding = AllowFieldHiding.Never; else field.Settings.AllowHiding = AllowFieldHiding.Default; } } }
}
I know that from the thread I mentioned on the OP. I was hoping for a solution more dynamic then hard code in every grid and every field.
See my classes about 50 all have an Id property (and other properties) which the end user should not see nor should they care, so putting the Browsable attrib was supposed to not expose the property to end user at all (at least in my mind) which is a good solution one place to change and property is still public so outside classes can use property. Also I like the grids to autogenerate fields that way all changes happen in the business layer and the presentation layer just exposes elements it should.
Only solution I can think of now is create a function using reflection to set AllowHiding to Never if Browsable = false. that will require me to make sure every grid is run through that function.
I'll post what I come up with.
Add this xaml to your project:
<igDP:Field Name="City">
<igDP:Field.Settings>
<igDP:FieldSettings AllowHiding="Never"/>
</igDP:Field.Settings>
</igDP:Field>
Forgot to attach project