RepositoryItemLookUpEdit.ForceInitialize() Method
Finishes the initialization of the LookUp editor’s data source. Call this method when the form is loading, before you start to create columns or obtain column values.
Namespace: DevExpress.XtraEditors.Repository
Assembly: DevExpress.XtraEditors.v24.1.dll
NuGet Package: DevExpress.Win.Navigation
Declaration
Remarks
The ForceInitialize
method initializes the editor’s data source so you can safely create columns or obtain column values on a form’s load (for instance, in the Form.Load
event handler).
Note
The ForceInitialize
method does not create lookup columns. Call the PopulateColumns() method to generate columns for the data source fields.
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 repositoryItemLookUpEdit = new RepositoryItemLookUpEdit();
repositoryItemLookUpEdit.DataSource = new List<DataObject> {
new DataObject { ID = 1, Text = "One" },
new DataObject { ID = 2, Text = "Two" },
new DataObject { ID = 3, Text = "Three" }
};
repositoryItemLookUpEdit.ValueMember = nameof(DataObject.ID);
repositoryItemLookUpEdit.DisplayMember = nameof(DataObject.Text);
// Initializes the lookup's data source and internal infrastructure.
repositoryItemLookUpEdit.ForceInitialize();
// Now, you can safely populate lookup columns.
repositoryItemLookUpEdit.PopulateColumns();
// Access columns and obtain column values.
var column = repositoryItemLookUpEdit.Columns[nameof(DataObject.Text)];
string columnValue = repositoryItemLookUpEdit.GetDataSourceValue(column, 1) as string; // columnValue = "Two"
object keyValue = repositoryItemLookUpEdit.GetKeyValueByDisplayValue(column); // keyValue = 2
}