Skip to main content

LookUpEdit.GetNotInListValue Event

Occurs when retrieving values for fields not found in the RepositoryItemLookUpEditBase.DataSource.

Namespace: DevExpress.XtraEditors

Assembly: DevExpress.XtraEditors.v23.2.dll

NuGet Package: DevExpress.Win.Navigation

Declaration

[DXCategory("Events")]
public event GetNotInListValueEventHandler GetNotInListValue

Event Data

The GetNotInListValue event's data class is GetNotInListValueEventArgs. The following properties provide information specific to this event:

Property Description
FieldName Gets the field for which you should provide the value for the specified record.
Value Gets or sets a field value.

Remarks

Lookup editors are capable of displaying unbound columns in the dropdown window, i.e. columns which are not bound to any field from the RepositoryItemLookUpEditBase.DataSource. Cell values for such columns are retrieved via the GetNotInListValue event.This event is also fired when RepositoryItemLookUpEditBase.DisplayMember or RepositoryItemLookUpEditBase.ValueMember properties refer to fields that are not found in the data source.

The editor’s GetNotInListValue event is equivalent to the RepositoryItemLookUpEdit.GetNotInListValue event available via the LookUpEdit.Properties object, i.e. adding/removing an event handler for the current event actually affects the RepositoryItemLookUpEdit.GetNotInListValue event.

Refer to the RepositoryItemLookUpEdit.GetNotInListValue topic for more information.

Example

The code below shows how to make a lookup editor display data from a custom array. The editor contains two columns. One column is bound to a field from the data source. The other column is unbound and is populated via the RepositoryItemLookUpEdit.GetNotInListValue event.

The data source of a lookup editor represents an array of Record class objects. The Record class declares the public Country property whose values are displayed in the column of the same name. The lookup editor also contains an ID column. Its field name (“ID”) does not coincide with any fields from the data source. So this column is unbound and is populated via the RepositoryItemLookUpEdit.GetNotInListValue event. In the event handler, we return the record id as a value for the column.

The following image shows the lookup editor after running this code:

LookUpEdit_GetNotInList_example

using DevExpress.XtraEditors.Controls;

//The class representing a row in a lookup editor
public class Record {
    private string country;
    public Record(string country) {
        this.country = country;
    }
    public string Country {
        get { return country; }
        set { country = value; }
    }
}

// ...
// An array of records displayed in the dropdown in the lookup editor
Record[] records = null;

//Fill the records array
private void InitData() {
    string[] data = (new string[] {"United States", "Afghanistan", "Albania", "Algeria",
  "Andorra", "Angola"});
    records = new Record[data.Length];
    for (int i = 0; i < data.Length; i++)
        records[i] = new Record(data[i]);
}

//Set up the lookup editor
private void InitLookUp() {
    //Specify an array of countries as a data source
    lookUpEdit2.Properties.DataSource = records;
    //The field whose values are displayed in the edit box
    lookUpEdit2.Properties.DisplayMember = "Country";
    //The field whose values match the edit value
    lookUpEdit2.Properties.ValueMember = "Country";

    //Unbound column
    lookUpEdit2.Properties.Columns.Add(new LookUpColumnInfo("ID", "ID", 20));
    //Column bound to the existing 'Country' field from the data source
    lookUpEdit2.Properties.Columns.Add(new LookUpColumnInfo("Country", "Country", 100));

    //Select the first record from the dropdown
    lookUpEdit2.EditValue = records[0].Country;
}


private void Form1_Load(object sender, System.EventArgs e) {
    InitData();
    InitLookUp();
}

private void lookUpEdit2_GetNotInListValue(object sender, GetNotInListValueEventArgs e) 
    //provide a value for the ID field
    if (e.FieldName == "ID")
        e.Value = e.RecordIndex.ToString() + ".";
}
See Also