Skip to main content

LookUpEdit.GetSelectedDataRow() Method

Returns a data source row corresponding to the currently selected edit value.

Namespace: DevExpress.XtraEditors

Assembly: DevExpress.XtraEditors.v24.2.dll

Declaration

public override object GetSelectedDataRow()

Returns

Type Description
Object

An object that represents a data source row corresponding to the currently selected edit value.

Remarks

The currently selected value is specified by the editor’s EditValue property. The GetSelectedDataRow method returns the data source row that contains this edit value in the key field, specified by the RepositoryItemLookUpEditBase.ValueMember property.

To get access to other data source rows by their key field values, use the RepositoryItemLookUpEdit.GetDataSourceRowByKeyValue method.

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.

LookUpEdit-GetSelectedDataRow-example.png

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"]);
    }
}
See Also