Skip to main content

RepositoryItemLookUpEdit.PopulateColumns() Method

Creates columns for all fields available in the lookup data source (RepositoryItemLookUpEditBase.DataSource).

Namespace: DevExpress.XtraEditors.Repository

Assembly: DevExpress.XtraEditors.v22.2.dll

NuGet Package: DevExpress.Win.Navigation


public virtual void PopulateColumns()


If no columns are explicitly created in the RepositoryItemLookUpEdit.Columns collection, the lookup editor automatically calls the PopulateColumns method to create columns at runtime when the editor’s dropdown is invoked for the first time.


When the form is loading, call the ForceInitialize() method, then call the PopulateColumns method before you start to create columns or obtain column values.

This example demonstrates how to initialize a LookUpEdit or its repository item during form load.

using DevExpress.XtraEditors.Repository;

private void Form1_Load(object sender, EventArgs e) {
    RepositoryItemLookUpEdit lookUpEdit = new RepositoryItemLookUpEdit();
    lookUpEdit.DataSource = new List<DataObject> {
        new DataObject { ID = 1, Text = "One" },
        new DataObject { ID = 2, Text = "Two" },
        new DataObject { ID = 3, Text = "Three" }
    lookUpEdit.ValueMember = nameof(DataObject.ID);
    lookUpEdit.DisplayMember = nameof(DataObject.Text);

    // Initializes the lookup's data source and internal infrustructure.

    // Now, you can safely populate lookup columns.

    // Access columns and obtain column values.
    var column = lookUpEdit.Columns[nameof(DataObject.Text)];
    string columnValue = lookUpEdit.GetDataSourceValue(column, 1) as string; // columnValue = "Two"
    object keyValue = lookUpEdit.GetKeyValueByDisplayValue(column); // keyValue = 2

The PopulateColumns method removes the existing columns from the RepositoryItemLookUpEdit.Columns collection and adds new columns to this collection for all fields in the RepositoryItemLookUpEditBase.DataSource. Use traditional collection methods to add, remove, and access individual lookup columns.

At design time, you can retrieve fields from the bound lookup data source and create corresponding columns via the control’s smart tag (for standalone editors) or by clicking the Populate Columns button in the Column Collection Editor. To activate this editor, click the ellipsis button for the RepositoryItemLookUpEdit.Columns property in the Properties window.

Each column in a lookup editor is an instance of the LookUpColumnInfo class. The PopulateColumns method sets the LookUpColumnInfo.FieldName and LookUpColumnInfo.Caption properties to the corresponding field names in the lookup data source.

If a field specifies a date/time value, the corresponding column’s LookUpColumnInfo.FormatType is set to FormatType.DateTime and FormatInfo.FormatString is set to the Short Date Format.

For numeric fields, the column’s LookUpColumnInfo.FormatType is set to FormatType.Numeric and the LookUpColumnInfo.Alignment is set to HorzAlignment.Far. For non-numeric fields, the alignment is set to HorzAlignment.Near.

After all columns have been created, the method calls RepositoryItemLookUpEdit.BestFit in order to calculate column widths according to their contents.

See Also