aspnetmvc-devexpress-dot-web-dot-mvc-dot-gridviewsettings-c39548fe.md
Provides access to a GridView’s column collection.
Namespace : DevExpress.Web.Mvc
Assembly : DevExpress.Web.Mvc5.v25.2.dll
NuGet Package : DevExpress.Web.Mvc5
public MVCxGridViewColumnCollection Columns { get; }
Public ReadOnly Property Columns As MVCxGridViewColumnCollection
| Type | Description |
|---|---|
| MVCxGridViewColumnCollection |
A MVCxGridViewColumnCollection object that is a collection of columns.
|
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.
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
GitHub example: How to hide and add columns in an exported document