Back to Devexpress

MVCxGridViewColumnCollection<RowType>.Add<ValueType>(Expression<Func<RowType, ValueType>>, Action<MVCxGridViewColumn<RowType>>) Method

aspnetmvc-devexpress-dot-web-dot-mvc-dot-mvcxgridviewcolumncollection-1-dot-add-1-x28-system-dot-linq-dot-expressions-dot-expression-system-dot-func-0-0-system-dot-action-devexpress-dot-web-dot-mvc-dot-mvcxgridviewcolumn-0-x29.md

latest3.8 KB
Original Source

MVCxGridViewColumnCollection<RowType>.Add<ValueType>(Expression<Func<RowType, ValueType>>, Action<MVCxGridViewColumn<RowType>>) Method

Adds a new column to the collection and allows you to bind this column to a model field via a lambda expression.

Namespace : DevExpress.Web.Mvc

Assembly : DevExpress.Web.Mvc5.v25.2.dll

NuGet Package : DevExpress.Web.Mvc5

Declaration

csharp
public MVCxGridViewColumn<RowType> Add<ValueType>(
    Expression<Func<RowType, ValueType>> expression,
    Action<MVCxGridViewColumn<RowType>> method
)
vb
Public Function Add(Of ValueType)(
    expression As Expression(Of Func(Of RowType, ValueType)),
    method As Action(Of MVCxGridViewColumn(Of RowType))
) As MVCxGridViewColumn(Of RowType)

Parameters

NameTypeDescription
expressionExpression<Func<RowType, ValueType>>

Identifies the data model field to which the column is bound.

| | method | Action<MVCxGridViewColumn<RowType>> |

A delegate method that accepts the created MVCxGridViewColumn<RowType> as a parameter.

|

Type Parameters

NameDescription
ValueType

The value type.

|

Returns

TypeDescription
MVCxGridViewColumn<RowType>

The grid view column.

|

Remarks

The following example illustrates how to use model-based properties and lambda expressions to create cell bands:

csharp
settings.Columns.Add(m => m.CustomerAddress, c => {
    c.Columns.Add(m => m.Country);
    c.Columns.Add(m => m.City);
    c.Columns.Add(m => m.Street);
});

or …

csharp
var cAdress = settings.Columns.Add(m => m.CustomerAddress, c => { c.Caption = "Address"; });
cAdress.Columns.Add(m => m.CustomerAddress.Country);
cAdress.Columns.Add(m => m.CustomerAddress.City);
cAdress.Columns.Add(m => m.CustomerAddress.Street);

… if your model class contains complex properties and you rely on complex properties’ types while using the Columns.Add method:

csharp
public class Customer {
    public Address CustomerAddress { get; set; }
}
public class Address {
    public string Country { get; set; }
    public string City { get; set; }
    public string Street { get; set; }
}

Breaking Change : T802552: GridView - The new Columns.Add method overload uses model-based properties and lambda expressions to create cell bands

See Also

MVCxGridViewColumnCollection<RowType> Class

MVCxGridViewColumnCollection<RowType> Members

DevExpress.Web.Mvc Namespace