Monday, October 26, 2009

How to Hide or Show an Property in the DetailView Against the Value of the Object's Property.

Here ItemName will be Enable/Disable According to IsApplicable Property

Assembly:
DevExpress.XtraLayout;
DevExpress.ExpressApp.Win.Layout;

if (View is DetailView && View.ObjectTypeInfo.Type == typeof(Item))
{
if (e.Object.GetType() == typeof(Item))
{
LayoutControl layoutControl = ((LayoutControl)View.Control);
DetailView dv = (DetailView)View;
Item itm = (Item)View.CurrentObject;
LayoutControlItem target = FindLayoutControlItemByName("ItemName", ((LayoutControl)(((WinLayoutManager)(dv.LayoutManager)).Container)).Items);
ITypeInfo imf = (ITypeInfo)XafTypesInfo.Instance.FindTypeInfo(View.CurrentObject.GetType());
IMemberInfo imi = imf.FindMember("IsApplicable");
Boolean ValueOfIsApplicable = false;
if (imi != null)
{
ValueOfIsApplicable = (Boolean)imi.GetValue(View.CurrentObject);
}
layoutControl.BeginUpdate();
if (target != null && ValueOfIsApplicable)
{
target.HideToCustomization();
}
else
{
target.RestoreFromCustomization();
}
layoutControl.EndUpdate();
}
}
Here is Method
private LayoutControlItem FindLayoutControlItemByName(string name, CollectionBase items)
{
foreach (object item in items)
{
if (item is LayoutControlItem)
{
if ((item as LayoutControlItem).ControlName != null)
{
if ((item as LayoutControlItem).ControlName.IndexOf(name) >= 0)
{
return item as LayoutControlItem;
}}}}
return null;
}

No comments:

Post a Comment

Mat Table Angular

Mat Table in Angular Mat table is used to display data . its a material designed styled data-table . For using Material Table MatTableMo...