You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WPF LookUpEdit控件无法填充数据问题求助

Fixing DevExpress LookUpEdit Data Population Issue in WPF

Hey there, let's get your LookUpEdit displaying data properly. I've spotted two key issues in your code that are preventing the control from populating correctly:

1. ItemsSource Needs a Collection (Not a Single Object)

The main problem is you're assigning a single Product instance to lookUpEdit1.ItemsSource, but LookUpEdit expects a collection type (like List<T>, ObservableCollection<T>, etc.) to display items—even if you only have one item to show. A single object can't be enumerated by the control, so it won't render any data.

2. (Optional) Use ObservableCollection for Dynamic Updates

If you plan to add/remove products later and want the UI to automatically reflect those changes, swap List<Product> with ObservableCollection<Product>. It implements INotifyCollectionChanged, which WPF uses to sync UI updates with data changes.


Corrected Backend Code

private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
    // Assign a collection instead of a single Product instance
    lookUpEdit1.ItemsSource = new List<Product> 
    {
        new Product("ad", "1", 5, 100),
        // Add more products here if needed
        new Product("Wireless Headphones", "2", 149.99, 35),
        new Product("Portable Charger", "3", 29.99, 80)
    };

    // For dynamic updates (uncomment below):
    // lookUpEdit1.ItemsSource = new ObservableCollection<Product>
    // {
    //     new Product("ad", "1", 5, 100)
    // };
}

class Product
{
    public string ProductName { get; set; }
    public string ID { get; set; }
    public double UnitPrice { get; set; }
    public int Quantity { get; set; }

    public Product(string productName, string id, double unitPrice, int quantity)
    {
        ProductName = productName;
        ID = id;
        UnitPrice = unitPrice;
        Quantity = quantity;
    }
}

Quick Note on Your XAML

Your XAML setup is actually spot-on:

  • The PART_GridControl naming is correct (DevExpress relies on this to link the GridControl to the LookUpEdit)
  • DisplayMember and ValueMember are properly mapped to your Product properties
  • Popup template columns are correctly bound to the Product fields

After making this change, your LookUpEdit should display the product data in both the input field and the popup grid.

内容的提问来源于stack exchange,提问作者B.Dikmenn

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:55:21