How to: Access the Grid Component in a List View
- 3 minutes to read
This article explains how to access properties of a grid component displayed in a List View. You can use this technique with any List Editor control.
Step-by-Step Instructions
- In Solution Explorer, navigate to:
- A platform-specific project in a .NET ASP.NET Core Blazor or Windows Forms application.
- A platform-specific module project in a .NET Framework ASP.NET Web Forms or Windows Forms application.
- Add a View Controller to the Controllers folder.
Inherit the controller from the
ObjectViewController<ViewType, ObjectType>
class and override theOnViewControlsCreated
method as demonstrated in the following code example:using DevExpress.Blazor; using DevExpress.ExpressApp; using DevExpress.ExpressApp.Blazor.Editors; using MainDemo.Module.BusinessObjects; using YourApplicationName.Module.BusinessObjects; namespace YourApplicationName.Blazor.Server.Controllers; public class EmployeeListViewController : ObjectViewController<ListView, Employee> { protected override void OnViewControlsCreated() { base.OnViewControlsCreated(); if(View.Editor is DxGridListEditor editor) { editor.GridModel.ColumnResizeMode = GridColumnResizeMode.ColumnsContainer; foreach(var columnModel in editor.GridDataColumnModels) { if(columnModel.FieldName == "Department.Title") { columnModel.FilterMenuButtonDisplayMode = GridFilterMenuButtonDisplayMode.Never; } columnModel.MinWidth = 50; } } } }
(Blazor only) The DxGridModel object replicates all parameters of the related DxGrid component. You can use these parameters to configure the underlying component before creation. However, the model does not allow you to access the current component state (for instance, a page index) or call its methods directly.
Use the ComponentInstance property to access the underlying component instance and its full API.
Platform-Specific Events for Control Customization
A View Item control or a List Editor control may not be ready for customization immediately after creation. If the technique described in this topic does not have the desired effect, handle platform-specific events listed below.
- Windows Forms:
The Control object’s HandleCreated, VisibleChanged, or ParentChanged event.
You can also handle
Load
or any similar event if the current control type exposes it.- ASP.NET Web Forms:
The Control object’s Load or Init server-side event.
Alternatively, you may need to handle the WebWindow.PagePreRender event. Use the CurrentRequestWindow static property to get the current WebWindow object.
If your application also requires customization on the client side, refer to the following topic for additional information: Client-Side Functionality.
- ASP.NET Core Blazor
- Handle the ComponentInstanceCaptured event to access underlying component instance and its full API. For more information, refer to the Handle Component Events section.