windowsforms-devexpress-dot-xtraeditors-dot-repository-dot-repositoryitemlookupedit-dot-getkeyvaluebydisplayvalue-x28-system-dot-object-x29.md
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.v25.2.dll
NuGet Package : DevExpress.Win.Navigation
public virtual object GetKeyValueByDisplayValue(
object displayValue
)
Public Overridable Function GetKeyValueByDisplayValue(
displayValue As Object
) As Object
| Name | Type | Description |
|---|---|---|
| displayValue | Object |
The value of the RepositoryItemLookUpEditBase.DisplayMember field for the row to locate.
|
| 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).
|
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.
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"]);
}
}
Private Sub SimpleButton1_Click(sender As Object, e As EventArgs) Handles SimpleButton1.Click
' Select a record in the LookUpEdit control
LookUpEdit1.EditValue = LookUpEdit1.Properties.GetKeyValueByDisplayValue("Condiments")
End Sub
Private Sub LookUpEdit1_EditValueChanged(sender As Object, e As EventArgs) Handles LookUpEdit1.EditValueChanged
Dim Lookup As LookUpEdit = CType(sender, LookUpEdit)
' Access the currently selected data row
Dim DataRow As DataRowView = CType(Lookup.GetSelectedDataRow(), DataRowView)
' Assign the row's Picture field value to the PictureEdit control
If Not DataRow Is Nothing Then
Dim imConverter As ImageConverter = New ImageConverter()
PictureEdit1.Image = CType(imConverter.ConvertFrom(DataRow("Picture")), Bitmap)
End If
End Sub
See Also
GetKeyValueByDisplayText(String)
GetDisplayValueByKeyValue(Object)
RepositoryItemLookUpEdit Class