Skip to main content

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.v24.2.dll

Declaration

public MVCxGridViewColumn<RowType> Add<ValueType>(
    Expression<Func<RowType, ValueType>> expression,
    Action<MVCxGridViewColumn<RowType>> method
)

Parameters

Name Type Description
expression Expression<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

Name Description
ValueType

The value type.

Returns

Type Description
MVCxGridViewColumn<RowType>

The grid view column.

Remarks

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

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 …

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:

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