Tab

GridLookupProperties.TextFormatString Property

Gets or sets the pattern used to format a selected item's text for display in the editor's edit box.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v20.2.dll

Declaration

public string TextFormatString { get; set; }

Property Value

Type Description
String

A string value that represents the format pattern.

Remarks

When an end-user selects items in the editor's dropdown list, each selected item is represented in the editor's edit box using a text value formatted based upon the TextFormatString property's setting. If multiple item selection is allowed (the GridLookupProperties.SelectionMode is set to GridLookupSelectionMode.Multiple), texts of different selected items are joined in the edit box using a special separator defined by the GridLookupProperties.MultiTextSeparator property.

By default, the TextFormatString property is set to an empty string. In this case, a textual representation of a selected item is composed from values of all data columns (GridViewDataColumn descendants) contained in the editor's ASPxGridLookup.Columns collection (GridLookupSettings.Columns in ASP.NET MVC GridLookup extension), regardless of the column visibility defined. The order of column values corresponds to the order in which data columns are listed in the Columns collection. Column values are separated wit a default separator represented by a semicolon and white space symbols.

GridLookup-TextFormatString-Default

The above image illustrates the editor defined using the following code.

@Html.DevExpress().GridLookup<Customer>(
    settings => {
        settings.Name = "gridLookup";
        settings.KeyFields(m => m.EmployeeID);

        settings.CommandColumn.Visible = true;
        settings.CommandColumn.ShowSelectCheckbox = true;

        settings.Columns.Add(m => m.EmployeeID).Visible = false;
        settings.Columns.Add(m => m.LastName).VisibleIndex = 2;
        settings.Columns.Add(m => m.FirstName).VisibleIndex = 3;
        settings.Columns.Add(m => m.BirthDate).VisibleIndex = 5;
        settings.Columns.Add(m => m.City).VisibleIndex = 6;
        settings.Columns.Add(m => m.Region).VisibleIndex = 7;
        settings.Columns.Add(m => m.Photo).VisibleIndex = 4;

        settings.Properties.SelectionMode = DevExpress.Web.GridLookupSelectionMode.Multiple;
        settings.Properties.Width = 450;
        settings.GridViewProperties.CallbackRouteValues = new { Controller = "GridLookup", Action = "LookupEditorPartial" };
}).Bind(Model).GetHtml()

You can use the TextFormatString property to provide a custom format for a selected item's value displayed in the editor's edit box. Set the property's value by using indexed placeholders (such as "{0}", "{1}", etc.), which can be combined with fixed literals and can contain standard or custom format strings. Placeholder indexes correspond to positions of data columns in the ASPxGridLookup.Columns collection (GridLookupSettings.Columns in ASP.NET MVC GridLookup extension). Command columns and band columns are not considered by placeholder indexes.

The following image illustrates a custom value set for the TextFormatString property in the editor whose markup was given above.

GridLookup-TextFormatString-Custom

If incremental filtering is used (the ASPxGridLookup.IncrementalFilteringMode property is not set to IncrementalFilteringMode.None), the value typed by an end-user in the edit box is searched in the editor's list, based upon the TextFormatString property's defined format.

refer to Selection Modes and Incremental Filtering topics to learn more.

See Also