RepositoryItemLookUpEdit.GetKeyValueByDisplayValue(Object) Method
Returns a value of the RepositoryItemLookUpEditBase.ValueMember field of the row containing the specified RepositoryItemLookUpEditBase.DisplayMember field value.
Namespace: DevExpress.XtraEditors.Repository
Assembly: DevExpress.XtraEditors.v24.1.dll
NuGet Package: DevExpress.Win.Navigation
Declaration
Parameters
Name | Type | Description |
---|---|---|
displayValue | Object | The value of the RepositoryItemLookUpEditBase.DisplayMember field for the row to locate. |
Returns
Type | Description |
---|---|
Object | The value of the RepositoryItemLookUpEditBase.ValueMember field for the row located.null if no record with the specified value was found (System.DBNull.Value when the data source is a DataView object). |
Remarks
The GetKeyValueByDisplayValue method searches for the record containing the specified display value (value of the RepositoryItemLookUpEditBase.DisplayMember field) and returns the key value it contains. The key value is retrieved from the RepositoryItemLookUpEditBase.ValueMember field of the record located.
This method returns the key value of the first record found.
RepositoryItemLookUpEditBase.ValueMember and RepositoryItemLookUpEditBase.DisplayMember properties represent the field names you need to specify to set up a lookup editor.
The row currently selected in a lookup editor is determined by the BaseEdit.EditValue property value and this matches the value of the rows’s RepositoryItemLookUpEditBase.ValueMember field. The value of the RepositoryItemLookUpEditBase.DisplayMember field of the selected row is displayed in the edit box.
To get the display value by the record’s key value, see the RepositoryItemLookUpEdit.GetDisplayValueByKeyValue function.
The RepositoryItemLookUpEdit.GetKeyValueByDisplayText and GetKeyValueByDisplayValue methods perform a search among rows that are present in the LookUp editor’s dropdown. If a target row has been hidden due to filtering (see RepositoryItemLookUpEdit.SearchMode), these methods will return null.
Example
In the following example, a LookUpEdit control is bound to the Categories table, which contains the CategoryID, CategoryName, Description and Picture fields. The control displays data from the first three fields. When you select a new record in the LookUpEditor (the control’s BaseEdit.EditValueChanged event), a separate PictureEdit control displays this record’s Picture field value.
private void simpleButton1_Click(object sender, EventArgs e) {
// Select a record in the LookUpEdit control
lookUpEdit1.EditValue = lookUpEdit1.Properties.GetKeyValueByDisplayValue("Condiments");
}
private void lookUpEdit1_EditValueChanged(object sender, EventArgs e) {
LookUpEdit lookUp = sender as LookUpEdit;
// Access the currently selected data row
DataRowView dataRow = lookUp.GetSelectedDataRow() as DataRowView;
// Assign the row's Picture field value to the PictureEdit control
if (dataRow != null) {
ImageConverter imConverter = new ImageConverter();
pictureEdit1.Image = (Bitmap)imConverter.ConvertFrom(dataRow["Picture"]);
}
}