windowsforms-devexpress-dot-xtraeditors-dot-lookupedit-7b5f7c81.md
Returns the data source record that matches the currently selected item.
Namespace : DevExpress.XtraEditors
Assembly : DevExpress.XtraEditors.v25.2.dll
NuGet Package : DevExpress.Win.Navigation
public override object GetSelectedDataRow()
Public Overrides Function GetSelectedDataRow As Object
| Type | Description |
|---|---|
| Object |
The data source record that corresponds to the currently selected item. null ( Nothing in Visual Basic) if the LookUpEdit.EditValue property is null or unassigned.
|
The GetSelectedDataRow method returns the record from the lookup’s data source that contains the value assigned to the LookUpEdit.EditValue property. The method searches for a match in the key field specified by the RepositoryItemLookUpEditBase.ValueMember property.
In multiple selection mode, the GetSelectedDataRow method behaves as follows:
Returns null ( Nothing in Visual Basic) if the EditValueType is set to LookUpEditValueType.CSVString.
Returns the first matching data source record if the EditValueType is set to LookUpEditValueType.ValueList. Use the GetSelectedDataRows() method to obtain data source records associated with the current selection.
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