RepositoryItemLookUpEdit.GetDataSourceRowByKeyValue(Object) Method
Returns a data source row containing the specified RepositoryItemLookUpEditBase.ValueMember field value.
Namespace: DevExpress.XtraEditors.Repository
Assembly: DevExpress.XtraEditors.v24.1.dll
NuGet Package: DevExpress.Win.Navigation
Declaration
Parameters
Name | Type | Description |
---|---|---|
keyValue | Object | The value of the RepositoryItemLookUpEditBase.ValueMember field for the row to be located. |
Returns
Type | Description |
---|---|
Object | An object representing the data source record containing the specified value. null (Nothing in Visual Basic) if no record with the specified value in the RepositoryItemLookUpEditBase.ValueMember field was found. |
Remarks
The lookup editor’s value is obtained from the data source field specified by the RepositoryItemLookUpEditBase.ValueMember property. The GetDataSourceRowByKeyValue method searches for the specified value within this field and returns an object representing the first found record.
The GetDataSourceRowByKeyValue method’s return value depends upon the type of the underlying data source. If the data source is a System.Data.DataTable or a System.Data.DataView, this method returns a System.Data.DataRowView object. If the data source is a custom list of items, the appropriate list item is returned.
Example
The following example shows how to customize a standalone Lookup editor to select a city:
In this example:
- Persons and Cities lists contain
Person
andCityInfo
objects.Person
objects are linked toCityInfo
objects. - The TextEdit and LookUpEdit controls edit the
Person.Name
andPerson.CityID
properties, respectively. - The lookup displays items from the Cities list.
- The DataNavigator control navigates between items in the Persons list.
using System;
using System.Windows.Forms;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
public Form1() {
InitializeComponent();
List<Person> dsPersons = Person.Init();
dataNavigator1.DataSource = dsPersons;
textEdit1.DataBindings.Add(new Binding("EditValue", dsPersons, "Name"));
lookUpEdit1.DataBindings.Add(new Binding("EditValue", dsPersons, "CityID"));
lookUpEdit1.Properties.DataSource = CityInfo.Init();
lookUpEdit1.Properties.ValueMember = "ID";
lookUpEdit1.Properties.DisplayMember = "City";
}
public class Person {
public string Name { get; set; }
public int CityID { get; set; }
static public List<Person> Init() {
return new List<Person>() {
new Person() { Name = "Carlos Gonzalez", CityID = 0 },
new Person() { Name = "Mario Pontes", CityID = 5 },
new Person() { Name = "Horst Kloss", CityID = 2 },
new Person() { Name = "Martin Sommer", CityID = 3 },
new Person() { Name = "Diego Roel", CityID = 3 },
new Person() { Name = "Catherine Dewey", CityID = 4 }
};
}
}
public class CityInfo {
int id;
public CityInfo(int id) {
this.id = id;
}
[Display(Order = -1)]
public int ID { get { return id; } }
public string City { get; set; }
public string Country { get; set; }
public string Region { get; set; }
static public List<CityInfo> Init() {
return new List<CityInfo>() {
new CityInfo(0) { City = "Barquisimeto", Country = "Venezuela", Region = "Lara" },
new CityInfo(1) { City = "Rio de Janeiro", Country = "Brazil", Region = "RJ" },
new CityInfo(2) { City = "Cunewalde", Country = "Germany", Region = "" },
new CityInfo(3) { City = "Madrid", Country = "Spain", Region = "" },
new CityInfo(4) { City = "Charleroi", Country = "Belgium", Region = "" },
new CityInfo(5) { City = "Sao Paulo", Country = "Brazil", Region = "SP" }
};
}
}
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the GetDataSourceRowByKeyValue(Object) method.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.