Skip to main content

GridViewSettings.Columns Property

Provides access to a GridView’s column collection.

Namespace: DevExpress.Web.Mvc

Assembly: DevExpress.Web.Mvc5.v22.1.dll

Declaration

public MVCxGridViewColumnCollection Columns { get; }

Property Value

Type Description
MVCxGridViewColumnCollection

A MVCxGridViewColumnCollection object that is a collection of columns.

Remarks

The Columns property stores a collection of MVCxGridViewColumn objects that denote columns. It provides methods that allow you to add new and remove existing columns. Individual columns can be accessed using indexed notation.

Refer to the Columns topic for more information.

Example

The following example illustrates how to use the GridViewSettings.Columns property.

Note

For a full example, see the Grid View - Column Moving demo.

@Html.DevExpress().GridView(settings => {
    settings.Name = "grid";
    settings.Columns.Add("ProductName");
    settings.Columns.Add("Category.CategoryName", MVCxGridViewColumnType.ComboBox);
    settings.Columns.Add("UnitPrice", MVCxGridViewColumnType.SpinEdit).PropertiesEdit.DisplayFormatString = "c";
    settings.Columns.Add("UnitsInStock", MVCxGridViewColumnType.SpinEdit);
    settings.Columns.Add(column => {
        column.FieldName = "Total";
        column.UnboundType = DevExpress.Data.UnboundColumnType.Integer;
        column.UnboundExpression = "UnitsInStock*UnitPrice";
        column.PropertiesEdit.DisplayFormatString = "c";
    });
    settings.Columns.Add(column => {
        column.FieldName = "Discontinued";
        column.ColumnType = MVCxGridViewColumnType.CheckBox;
        column.Width = 80;
        column.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
    });
    ...
}).Bind(Model).GetHtml()
See Also