LookUpEdit.GetSelectedDataRow() Method
Returns the data source record that matches the currently selected item.
Namespace: DevExpress.XtraEditors
Assembly: DevExpress.XtraEditors.v25.1.dll
NuGet Package: DevExpress.Win.Navigation
Declaration
Returns
Type | Description |
---|---|
Object | The data source record that corresponds to the currently selected item. null (Nothing in Visual Basic) if the |
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
.// Enable `CSVString` multiple selection mode. lookUpEdit1.Properties.EditValueType = LookUpEditValueType.CSVString; // Display the checkbox selector column. lookUpEdit1.Properties.AddCheckBoxSelectorColumn(); // Select the first three items in the lookup editor. lookUpEdit1.EditValue = "0,1,2"; object selectedDataRow = lookUpEdit1.GetSelectedDataRow(); // Returns null. object selectedDataRows = lookUpEdit1.GetSelectedDataRows(); // Returns null.
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.// Enable `ValueList` multiple selection mode. lookUpEdit1.Properties.EditValueType = LookUpEditValueType.ValueList; // Display the checkbox selector column. lookUpEdit1.Properties.AddCheckBoxSelectorColumn(); // Select the first three items in the lookup editor. lookUpEdit1.EditValue = new List<int>(){ 0, 1, 2 }; object selectedDataRow = lookUpEdit1.GetSelectedDataRow(); // Returns the first matching data source record. object selectedDataRows = lookUpEdit1.GetSelectedDataRows(); // Returns 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.
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"]);
}
}