Example T371660
Visible to All Users

WinForms Lookup - Create cascading lookup editors

LookUpEdit, GridLookUpEdit, and SearchLookUpEdit controls can automatically filter their data sources based on a value in another lookup.

Use the secondary lookup's CascadingOwner property to specify the primary lookup. Lookups use an internal algorithm that identifies a key field in a data source. The algorithm checks the names of data objects, the key attributes, and the data type of the primary keys. The algorithm is based on a common naming convention of key fields (for example, ID, Key, and OID).

Use the CascadingMember property to manually specify a key field of the secondary lookup if the lookup's algorithm cannot identify a key field. Use the ; character to delimit field names in a compound foreign key field.

Read the following help topic for additional information: Cascading Lookups.

Files to Review

Documentation

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

DXApplication1/DataProvider.cs(vb)
C#
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace DXApplication1 { public class DataProvider { public static BindingList<Category> GetCategoryList(int recordCount = 10) { BindingList<Category> list = new BindingList<Category>(); for (int i = 0; i < recordCount; i++) { list.Add(new Category(i) { CategoryName = string.Format("Text {0}", i) }); } return list; } public static BindingList<Product> GetProductList(int recordCount = 15) { BindingList<Product> list = new BindingList<Product>(); for (int i = 0; i < recordCount; i++) { list.Add(new Product(i) { CategoryID = i % 5, Description = string.Format("Description {0}", i), ProductName = string.Format("Product {0}", i) }); } return list; } public static BindingList<Order> GetOrderList(int recordCount = 25) { BindingList<Order> list = new BindingList<Order>(); for (int i = 0; i < recordCount; i++) { list.Add(new Order(i) { ProductID = i % 15, OrderNumber = 1000 + i }); } return list; } } public class Category { public Category(int id) { ID = id; } public int ID { get; private set; } public string CategoryName { get; set; } } public class Product { public Product(int id) { ID = id; } public int ID { get; private set; } public int CategoryID { get; set; } public string ProductName { get; set; } public string Description { get; set; } } public class Order { public Order(int id) { ID = id; } public int ID { get; private set; } public int ProductID { get; set; } public int OrderNumber { get; set; } } }
DXApplication1/Main.cs(vb)
C#
using System; using System.Collections.Generic; using System.Linq; using DevExpress.XtraEditors; namespace DXApplication1 { public partial class Main : DevExpress.XtraEditors.XtraForm { public Main() { InitializeComponent(); lookUpEdit1.Properties.PopupFilterMode = DevExpress.XtraEditors.PopupFilterMode.Contains; SetupLookUpEditor(gridLookUpEdit1, DataProvider.GetCategoryList(), "ID", "CategoryName"); SetupLookUpEditor(lookUpEdit1, DataProvider.GetProductList(), "ID", "ProductName", gridLookUpEdit1); SetupLookUpEditor(searchLookUpEdit1, DataProvider.GetOrderList(), "ID", "OrderNumber", lookUpEdit1); } private void SetupLookUpEditor(LookUpEditBase lookup, object dataSource, string valueMember, string displayMember, LookUpEditBase lookupOwner = null) { lookup.Properties.DataSource = dataSource; lookup.Properties.ValueMember = valueMember; lookup.Properties.DisplayMember = displayMember; lookup.CascadingOwner = lookupOwner; } } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.