The RepositoryItemLookUpEdit class contains settings specific to the GridLookUpEdit control. You can access these settings via the editor's GridLookUpEdit.Properties object. See the GridLookUpEdit topic for details on the control.
You need to create repository items as standalone objects only to specify inplace editors for container controls (such as the XtraGrid, XtraTreeList, etc).
Note
The GridLookUpEdit and SearchLookUpEdit controls do not have a connection to their underlying data sources while their dropdown windows are closed.
So in this instance it is not possible to access the underlying data or a grid's calculated data using methods provided by the embedded Grid Control and its View. You can use these methods only when the controls' dropdown windows are open.
While the dropdown windows are closed, you can access the underlying data using methods provided by the underlying data source.

Example
The following example demonstrates how to create and customize a GridLookUpEdit control at runtime.
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.
The result of the example is shown in the following image:

C# |
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Columns;
using System.Data.OleDb;
GridLookUpEdit gridLookup;
DataNavigator dataNav;
DataView dvMain;
DataView dvDropDown;
private void Form1_Load(object sender, System.EventArgs e) {
gridLookup = new GridLookUpEdit();
gridLookup.Bounds = new Rectangle(10, 40, 200, 20);
this.Controls.Add(gridLookup);
dataNav = new DataNavigator();
dataNav.Bounds = new Rectangle(10, 10, 250, 20);
this.Controls.Add(dataNav);
InitData();
InitLookUp();
dataNav.DataSource = dvMain;
}
private void InitData() {
DataSet ds = new DataSet();
string connestionString =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\DB\\nwind.mdb";
System.Data.OleDb.OleDbDataAdapter dbAdapter =
new OleDbDataAdapter("SELECT * FROM [Order Details]", connestionString);
dbAdapter.Fill(ds, "Order Details");
dbAdapter = new OleDbDataAdapter("SELECT * FROM Products", connestionString);
dbAdapter.Fill(ds, "Products");
DataViewManager dvm = new DataViewManager(ds);
dvMain = dvm.CreateDataView(ds.Tables["Order Details"]);
dvDropDown = dvm.CreateDataView(ds.Tables["Products"]);
}
private void InitLookUp() {
gridLookup.DataBindings.Add("EditValue", dvMain, "ProductID");
gridLookup.Properties.PopupView.OptionsBehavior.AutoPopulateColumns = false;
gridLookup.Properties.DataSource = dvDropDown;
gridLookup.Properties.DisplayMember = "ProductName";
gridLookup.Properties.ValueMember = "ProductID";
GridColumn col1 = gridLookup.Properties.PopupView.Columns.AddField("ProductID");
col1.VisibleIndex = 0;
col1.Caption = "Product ID";
GridColumn col2 = gridLookup.Properties.PopupView.Columns.AddField("ProductName");
col2.VisibleIndex = 1;
col2.Caption = "Product Name";
gridLookup.Properties.PopupView.BestFitColumns();
gridLookup.Properties.PopupFormWidth = 300;
}
|
VB |
Imports DevExpress.XtraEditors
Imports DevExpress.XtraGrid.Columns
Imports System.Data.OleDb
Dim gridLookup As GridLookUpEdit
Dim dataNav As DataNavigator
Dim dvMain As DataView
Dim dvDropDown As DataView
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
gridLookup = New GridLookUpEdit()
gridLookup.Bounds = New Rectangle(10, 40, 200, 20)
Me.Controls.Add(gridLookup)
dataNav = New DataNavigator()
dataNav.Bounds = New Rectangle(10, 10, 250, 20)
Me.Controls.Add(dataNav)
InitData()
InitLookUp()
dataNav.DataSource = dvMain
End Sub
Private Sub InitData()
Dim ds As New DataSet()
Dim connestionString As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\DB\nwind.mdb"
Dim dbAdapter As New OleDbDataAdapter("SELECT * FROM [Order Details]", connestionString)
dbAdapter.Fill(ds, "Order Details")
dbAdapter = New OleDbDataAdapter("SELECT * FROM Products", connestionString)
dbAdapter.Fill(ds, "Products")
Dim dvm As New DataViewManager(ds)
dvMain = dvm.CreateDataView(ds.Tables("Order Details"))
dvDropDown = dvm.CreateDataView(ds.Tables("Products"))
End Sub
Private Sub InitLookUp()
gridLookup.DataBindings.Add("EditValue", dvMain, "ProductID")
gridLookup.Properties.PopupView.OptionsBehavior.AutoPopulateColumns = False
gridLookup.Properties.DataSource = dvDropDown
gridLookup.Properties.DisplayMember = "ProductName"
gridLookup.Properties.ValueMember = "ProductID"
Dim col1 As GridColumn = gridLookup.Properties.PopupView.Columns.AddField("ProductID")
col1.VisibleIndex = 0
col1.Caption = "Product ID"
Dim col2 As GridColumn = gridLookup.Properties.PopupView.Columns.AddField("ProductName")
col2.VisibleIndex = 1
col2.Caption = "Product Name"
gridLookup.Properties.PopupView.BestFitColumns()
gridLookup.Properties.PopupFormWidth = 300
End Sub
|