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
- DataProvider.cs (VB: DataProvider.vb)
- Main.cs (VB: Main.vb)
Documentation
Does this example address your development requirements/objectives?
(you will be redirected to DevExpress.com to submit your response)
Example Code
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; }
}
}
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;
}
}
}