I added a custom attribute to change displayname.
public GridColumnAttribute(string DisplayName, string SummaryText,
SummaryTypes SummaryType)
{
this.DisplayName = DisplayName;
this.SummaryText = SummaryText;
this.SummaryType = SummaryType;
}
I used that display name in my business class.
MemberInfo property =
typeof(MeterProfileCustomDTO).GetRuntimeProperty("ComsumptionPeriod01");
var attribute =
property.GetCustomAttributes(typeof(GridColumnAttribute),
true).Cast<GridColumnAttribute>().Single();
attribute.DisplayName = "Trial";
// Create a PropertyDescriptor for "SpouseName" by
calling the static GetProperties on TypeDescriptor.
PropertyDescriptor descriptor =
TypeDescriptor.GetProperties(periodItem.GetType())["ComsumptionPeriod01"];
// Fetch the ReadOnlyAttribute from the descriptor.
GridColumnAttribute attrib =
(GridColumnAttribute)descriptor.Attributes[typeof(GridColumnAttribute)];
// Get the internal isReadOnly field from the
ReadOnlyAttribute using reflection.
FieldInfo isReadOnly = attrib.GetType().GetField("DisplayName",
BindingFlags.NonPublic | BindingFlags.Instance);
// Using Reflection, set the internal isReadOnly field.
isReadOnly.SetValue(attrib, "2018-01");
I want to change this displayname at runtime. enter image description here
Comments
Post a Comment