Not auto-generate a column for a specific property

As you know, if the AutoGenerateColumns="True" (which is by default), RadGridView will create a column for each property of the underlying business object. This article shows how to not auto generate a column for a specific property.

There are two methods to accomplish this:

  1. Using [DataAnnotations](http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.aspx?appId=Dev10IDEF1&l=EN-US&k=k(SYSTEM.COMPONENTMODEL.DATAANNOTATIONS.DISPLAYATTRIBUTE.AUTOGENERATEFIELD);k(AUTOGENERATEFIELD);k(TargetFrameworkMoniker-).

In this approach you need to add a reference to the System.ComponentModel.DataAnnotations assembly and mark your property with the [Display(AutoGenerateField = false)]

Here is an example:

C#

[Display(AutoGenerateField = false)] 
public ObservableCollection<Player> Players
{
 get
 {
  if (null == this.players)
  {
   this.players = new ObservableCollection<Player>();
  }
  return this.players;
 }
}

Now, RadGridView will not create a column for the Players property.

  1. Canceling the AutoGeneratingColumn event for the particular column:

C#

private void clubsGrid_AutoGeneratingColumn(object sender, GridViewAutoGeneratingColumnEventArgs e)
{
   if (e.Column.UniqueName == "Players")
   {
      e.Cancel = true;
   }
}