Back to Devexpress

LookUpEdit.GetSelectedDataRow() Method

windowsforms-devexpress-dot-xtraeditors-dot-lookupedit-7b5f7c81.md

latest4.7 KB
Original Source

LookUpEdit.GetSelectedDataRow() Method

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

Declaration

csharp
public override object GetSelectedDataRow()
vb
Public Overrides Function GetSelectedDataRow As Object

Returns

TypeDescription
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.

|

Remarks

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.

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.

csharp
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"]);
    }
}
vb
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

GetSelectedDataRows()

LookUpEdit Class

LookUpEdit Members

DevExpress.XtraEditors Namespace