How To - Create and Customize A GridLookUpEdit Control at Runtime - WinForms Controls - DevExpress Help
How To - Create and Customize A GridLookUpEdit Control at Runtime - WinForms Controls - DevExpress Help
WinForms Controls > Controls and Libraries > Data Grid > Examples > How to: Create and Customize a
In the example, a lookup editor will be used to edit the values of the "ProductID" field in the "Order
Details" table (NWind database). It must display a list of the available products in the dropdown, which
are stored in the "Products" table in the NWind database. By selecting a row from the dropdown an
end-user will change the current order's product. Also a data navigator will be created that will assist an
end-user to navigate through the "Order Details" table.
To implement the required functionality the following key properties of the lookup editor must be set:
The editor's BaseEdit.EditValue property is bound to the "ProductID" field in the "Order Details"
table via the DataBindings property.
The editor's RepositoryItemLookUpEditBase.DataSource property is set to a DataView object
which contains rows from the "Products" table in the NWind database.
The editor's RepositoryItemLookUpEditBase.ValueMember property is set to the "ProductID" field
in the "Products" table. This field's value must match the editor's edit value, and so the
"ProductID" field in the "Order Details" table.
The editor's RepositoryItemLookUpEditBase.DisplayMember property is set to the "ProductName"
field in the "Products" table. This identifies the field in the DataSource whose values match the
editor's display text.
Two columns are created within the underlying View via the ColumnView.Columns property.
These will display values from the "ProductID" and "ProductName" fields in the dropdown data
source.
https://documentation.devexpress.com/WindowsForms/3004/Controls-and-Libraries/Data-Grid/Examples/Data-Binding/How-to-Create-and-Customize-… 1/6
3/25/2020 How to: Create and Customize a GridLookUpEdit Control at Runtime | WinForms Controls | DevExpress Help
C# VB
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Columns;
using System.Data.OleDb;
//...
InitData();
InitLookUp();
dataNav.DataSource = dvMain;
}
string connestionString =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\DB\\nwind.mdb";
// Prevent columns from being automatically created when a data source is assigned.
gridLookup.Properties.PopupView.OptionsBehavior.AutoPopulateColumns = false;
// The data source for the dropdown rows
gridLookup.Properties.DataSource = dvDropDown;
// The field for the editor's display text.
gridLookup.Properties.DisplayMember = "ProductName";
// The field matching the edit value.
Is this topic helpful?
gridLookup.Properties.ValueMember = "ProductID";
Imports DevExpress.XtraEditors
Imports DevExpress.XtraGrid.Columns
Imports System.Data.OleDb
'...
InitData()
InitLookUp()
dataNav.DataSource = dvMain
End Sub
connestionString)
' Load data from the "Order Details" table to the dataset
dbAdapter.Fill(ds, "Order Details")
' Connect to the "Products" table
dbAdapter = New OleDbDataAdapter("SELECT * FROM Products", connestionString)
' Load data from the "Products" table into the dataset
dbAdapter.Fill(ds, "Products")
' Prevent columns from being automatically created when a data source is assigned.
gridLookup.Properties.PopupView.OptionsBehavior.AutoPopulateColumns = False
' The data source for the dropdown rows
gridLookup.Properties.DataSource = dvDropDown
' The field for the editor's display text.
gridLookup.Properties.DisplayMember = "ProductName"
' The field matching the edit value.
gridLookup.Properties.ValueMember = "ProductID"
End Sub
https://documentation.devexpress.com/WindowsForms/3004/Controls-and-Libraries/Data-Grid/Examples/Data-Binding/How-to-Create-and-Customize-… 6/6