Skip to main content
All docs
V25.1
  • .NET 8.0+
    • The page you are viewing does not exist in the .NET Framework 4.6.2+ platform documentation. This link will take you to the parent topic of the current section.

    DxGridListEditorBase.AddColumnModel(DxDataColumnBaseModel) Method

    Adds an unbound column to the DxGridListEditor.

    Namespace: DevExpress.ExpressApp.Blazor.Editors

    Assembly: DevExpress.ExpressApp.Blazor.v25.1.dll

    NuGet Package: DevExpress.ExpressApp.Blazor

    Declaration

    public void AddColumnModel(
        DxDataColumnBaseModel dataColumnModel
    )

    Parameters

    Name Type Description
    dataColumnModel DevExpress.ExpressApp.Blazor.Editors.Models.DxDataColumnBaseModel

    The Component Model that allows you to configure column properties such as the field name, caption, visibility, sorting, and format.

    Remarks

    The following code snippet adds two columns to the Grid:

    • Total - specifies the UnboundExpression property to calculate values.
    • Result- uses the UnboundColumnData event handler to obtain data (see the next code snippet).
    using DevExpress.Blazor;
    using DevExpress.ExpressApp.Blazor.Editors;
    using DevExpress.ExpressApp;
    using MySolutionName.Module.BusinessObjects;
    using DevExpress.ExpressApp.Blazor.Editors.Models;
    
    namespace MySolutionName.Blazor.Server.Controllers;
    public class UnboundColumnController : ObjectViewController<ListView, TestObjects> {
        protected override void OnViewControlsCreated() {
            if (View.Editor is DxGridListEditor editor) {
                //Add an unbound column
                editor.AddColumnModel(
                    new DxGridDataColumnModel() {
                        FieldName = "Total",
                        Caption = "Total",
                        Visible = true,
                        VisibleIndex = 5,
                        UnboundType = GridUnboundColumnType.Integer,
                        UnboundExpression = "Number1 + Number2 + Number3"
                    }
                );
                editor.AddColumnModel(
                    new DxGridDataColumnModel() {
                        FieldName = "Result",
                        Caption = "Result",
                        Visible = true,
                        VisibleIndex = 6,
                        UnboundType = GridUnboundColumnType.String,
                    }
                );
            }
            base.OnViewControlsCreated();
        }
    }
    

    The following code handles the UnboundColumnData event to supply values to the Result column based on Total column values:

    using DevExpress.Blazor;
    using DevExpress.ExpressApp.Blazor.Editors;
    using DevExpress.ExpressApp;
    using MySolutionName.Module.BusinessObjects;
    using DevExpress.ExpressApp.Blazor.Editors.Models;
    
    namespace MySolutionName.Blazor.Server.Controllers;
    public class UnboundColumnController : ObjectViewController<ListView, TestObjects> {
        protected override void OnViewControlsCreated() {
            if (View.Editor is DxGridListEditor editor) {
                // Obtain an unbound column by field name
                editor.GridModel.UnboundColumnData = (args) => {
                    if(args.FieldName == "Result") {
                        var total = (int)args.GetRowValue("Total");
                        if(total > 0)
                            args.Value = "Positive";
                        else if(total == 0)
                            args.Value = "Zero";
                        else
                            args.Value = "Negative";
                    }
                };
            }
            base.OnViewControlsCreated();
        }
    }
    
    See Also