WPF Controls lookupedit, I can not fill in the lookupedit

793 Views Asked by At

.xaml

 <Grid>
        <dxg:LookUpEdit Name="lookUpEdit1"
                        DisplayMember="ProductName"
                        ValueMember="ID"
                        AutoPopulateColumns="False"
                        AutoComplete="True"
                        IncrementalFiltering="True"
                        ImmediatePopup="True"
                        IsPopupAutoWidth="False"
                        HorizontalAlignment="Center"
                        VerticalAlignment="Top"
                        Width="200" Margin="10">
            <dxg:LookUpEdit.PopupContentTemplate>
                <ControlTemplate>
                    <dxg:GridControl Name="PART_GridControl">
                        <dxg:GridControl.Columns>
                            <dxg:GridColumn FieldName="ProductName"/>
                            <dxg:GridColumn FieldName="UnitPrice"/>
                            <dxg:GridColumn FieldName="Quantity"/>
                        </dxg:GridControl.Columns>
                        <dxg:GridControl.View>
                            <dxg:TableView AutoWidth="True"/>
                        </dxg:GridControl.View>
                    </dxg:GridControl>
                </ControlTemplate>
            </dxg:LookUpEdit.PopupContentTemplate>
        </dxg:LookUpEdit>
    </Grid>

MainWindow_Loaded{

lookUpEdit1.ItemsSource = 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;
        }
    }

enter image description here

As you see the codes. I can not fill you in as you see.I'm waiting for your help..

1

There are 1 best solutions below

0
On

The ItemsSource property is expecting any object that derives from IEnumerable, as your setting a single Product, the underlying GridControl doesn't know what to do with it.

To fix, just set ItemsSource to a list of Products instead.

More info here