Enumerating Lists in .NET

Less than one minute read time.

Below is a small snippet of code that shows how Lists can be enumerated within code.

I needed to carry out a task that would cycle through the fields of a List block allowing me to set some properties.

The code assumes the following usings


using System.Collections.Generic;
using Sage.CRM.WebObject;
using Sage.CRM.Utils;
using Sage.CRM.Controls;

The sample below was party of a Web class that pulling data back from an external database table. And in this example I needed to switch off the display of fields where the user did not have the rights to view the system entity Opportunity.

The extract of code looked like this


string strListBlockName = "ExternalTableList";
List listBlock = new List(strListBlockName);
IEnumerator myfields = listBlock.GetEnumerator();
while (myfields.MoveNext())
{
if (!CurrentUser.HasRights(Sage.PermissionType.View, "Opportunity"))
{
    myfields.Current.IsVisible = false;
}
//AddContent(myfields.Current.Name);
}

Within a ListPage specialised class the default List used is called ResultsGrid. See the article "Customizing the FilterBox (FilterScreen) and the List (ResultsGrid) in a ListPage Class".

The code would be simpler


IEnumerator myfields = ResultsGrid.GetEnumerator();
while (myfields.MoveNext())
{
if (!CurrentUser.HasRights(Sage.PermissionType.View, "Opportunity"))
{
    myfields.Current.IsVisible = false;
}
}

Parents Comment Children
No Data