Back to Devexpress

LookUpEdit.GetNotInListValue Event

windowsforms-devexpress-dot-xtraeditors-dot-lookupedit-9141a732.md

latest8.1 KB
Original Source

LookUpEdit.GetNotInListValue Event

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

Namespace : DevExpress.XtraEditors

Assembly : DevExpress.XtraEditors.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
[DXCategory("Events")]
public event GetNotInListValueEventHandler GetNotInListValue
vb
<DXCategory("Events")>
Public Event GetNotInListValue As GetNotInListValueEventHandler

Event Data

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

PropertyDescription
FieldNameGets the field for which you should provide the value for the specified record.
ValueGets 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:

csharp
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() + ".";
}
vb
'The class representing a row in a lookup editor
Public Class Record
    Private _country As String
    Public Sub New(ByVal _country As String)
        Me._country = _country
    End Sub
    Public Property Country() As String
        Get
            Return _country
        End Get
        Set(ByVal Value As String)
            _country = Value
        End Set
    End Property
End Class

' ...
'An array of records displayed in the dropdown in the lookup editor
Dim records() As Record = Nothing

'Fill the records array
Private Sub InitData()
    Dim _data() As String = New String() {"United States", "Afghanistan", "Albania", _
      "Algeria", "Andorra", "Angola"}
    records = New Record(_data.Length - 1) {}
    Dim I
    For I = 0 To _data.Length - 1
        records(I) = New Record(_data(I))
    Next
End Sub

'Set up the lookup editor
Private Sub 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
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
  Handles MyBase.Load
    InitData()
    InitLookUp()
End Sub

Private Sub LookUpEdit2_GetNotInListValue(ByVal sender As Object, _
  ByVal e As DevExpress.XtraEditors.Controls.GetNotInListValueEventArgs) _
  Handles LookUpEdit2.GetNotInListValue
    'provide a value for the ID field
    If (e.FieldName = "ID") Then e.Value = e.RecordIndex.ToString() + "."
End Sub

See Also

GetNotInListValue

LookUpEdit Class

LookUpEdit Members

DevExpress.XtraEditors Namespace