windowsforms-devexpress-dot-xtraeditors-dot-repository-dot-repositoryitemlookupedit-6c3e9966.md
Occurs after the DataSource property has been changed.
Namespace : DevExpress.XtraEditors.Repository
Assembly : DevExpress.XtraEditors.v25.2.dll
NuGet Package : DevExpress.Win.Navigation
[DXCategory("Events")]
public event EventHandler DataSourceChanged
<DXCategory("Events")>
Public Event DataSourceChanged As EventHandler
The DataSourceChanged event's data class is EventArgs.
The following example shows how to bind a lookup editor to data created at runtime:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
public partial class Form1 : DevExpress.XtraEditors.XtraForm {
public Form1() {
InitializeComponent();
// Binds the lookup to data.
lookUpEdit1.Properties.DataSource = Employee.GetSampleData();
// Sets the lookup's data fields.
lookUpEdit1.Properties.DisplayMember = "FullName";
lookUpEdit1.Properties.ValueMember = "ID";
// Sets the lookup's value. Selects the first record.
lookUpEdit1.EditValue = 0;
}
}
public class Employee {
public Employee(int iD, string firstName, string lastName) {
ID = iD;
FirstName = firstName;
LastName = lastName;
}
public static List<Employee> GetSampleData() {
return new List<Employee>() {
new Employee(0, "Bart", "Arnaz"),
new Employee(1, "Leah", "Simpson"),
new Employee(2, "Arnold", "Schwartz"),
new Employee(3, "William", "Zimmer"),
new Employee(4, "Samantha", "Piper")
};
}
// The 'ID' field must contain unique values.
public int ID { get; private set; }
public string FirstName { get; set; }
public string LastName { get; set; }
[Display(Order = -1)]
public string FullName {
get {
return string.Format("{0} {1}", FirstName, LastName);
}
}
}
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel.DataAnnotations
Partial Public Class Form1
Inherits DevExpress.XtraEditors.XtraForm
Public Sub New()
InitializeComponent()
' Binds the lookup to data.
lookUpEdit1.Properties.DataSource = Employee.GetSampleData()
' Sets the lookup's data fields.
lookUpEdit1.Properties.DisplayMember = "FullName"
lookUpEdit1.Properties.ValueMember = "ID"
' Sets the lookup's value.
lookUpEdit1.EditValue = 0
End Sub
End Class
Public Class Employee
Public Sub New(ByVal iD As Integer, ByVal firstName As String, ByVal lastName As String)
Me.ID = iD
Me.FirstName = firstName
Me.LastName = lastName
End Sub
Public Shared Function GetSampleData() As List(Of Employee)
Return New List(Of Employee)() From {
New Employee(0, "Bart", "Arnaz"),
New Employee(1, "Leah", "Simpson"),
New Employee(2, "Arnold", "Schwartz"),
New Employee(3, "William", "Zimmer"),
New Employee(4, "Samantha", "Piper")
}
End Function
' The 'ID' field must contain unique values.
Private privateID As Integer
Public Property ID() As Integer
Get
Return privateID
End Get
Private Set(ByVal value As Integer)
privateID = value
End Set
End Property
Public Property FirstName() As String
Public Property LastName() As String
<Display(Order := -1)>
Public ReadOnly Property FullName() As String
Get
Return String.Format("{0} {1}", FirstName, LastName)
End Get
End Property
End Class
The image below shows the result.
See Also
RepositoryItemLookUpEdit Class