Back to Devexpress

RepositoryItemLookUpEditBase.KeyMember Property

windowsforms-devexpress-dot-xtraeditors-dot-repository-dot-repositoryitemlookupeditbase-4e073ff7.md

latest4.3 KB
Original Source

RepositoryItemLookUpEditBase.KeyMember Property

Gets or sets a string that specifies a key field (or multiple key fields) used for business object identification (when a lookup editor is bound to a business object).

Namespace : DevExpress.XtraEditors.Repository

Assembly : DevExpress.XtraEditors.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
[DefaultValue("")]
[DXCategory("Data")]
public virtual string KeyMember { get; set; }
vb
<DXCategory("Data")>
<DefaultValue("")>
Public Overridable Property KeyMember As String

Property Value

TypeDefaultDescription
StringString.Empty

A string that specifies a key field or multiple key fields delimited by the ‘;’ character.

|

Remarks

When a lookup editor is bound to a business object (not to a value of a simple type), you must assign the business object’s key field to the KeyMember property to allow for proper business object identification.

If a business object has multiple key fields, specify all these key field names in the KeyMember property value, by delimiting them with the ‘;’ character. For instance:

csharp
lookUpEdit1.Properties.KeyMember = "OrderID;ProductID";

At design time, you can set the KeyMember property in the Properties window using a dedicated editor, which shows all available fields from the bound lookup data source.

When an end-user selects a certain lookup record in the dropdown, this record (the object that encapsulates this record) is assigned to the lookup editor’s edit value. Ensure that the data type of lookup records is accepted by the editor’s edit value.

For more information and an example, see Advanced Binding (to Business Objects).

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the KeyMember property.

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.

winforms-cascading-standalone-lookups/CS/Lookup-Cascading/Form1.cs#L28

csharp
lookUpEdit1.Properties.DisplayMember = "CategoryName";
lookUpEdit1.Properties.KeyMember = "Key";

winforms-cascading-standalone-lookups/VB/Lookup-Cascading/Form1.vb#L30

vb
lookUpEdit1.Properties.DisplayMember = "CategoryName"
lookUpEdit1.Properties.KeyMember = "Key"

See Also

Advanced Binding (to Business Objects)

RepositoryItemLookUpEditBase Class

RepositoryItemLookUpEditBase Members

DevExpress.XtraEditors.Repository Namespace