KB Article T929986
Visible to All Users

DevExpress WinForms Troubleshooting - LookUp Editors

Cheat Sheets, Best Practices and Troubleshooting


All Lookup Editors (LookUpEdit, GridLookUpEdit, SearchLookUpEdit and TreeListLookUpEdit) share the same customization principles. In standard binding mode, you need to correctly set up the following properties for your lookup editor:

This article describes the most common issues that you may face when using any lookup editor.

Known Issues

Issue 1. You are using a lookup control as a column editor and its text disappears after you focus another cell.

Solution: Please refer to the following article to learn how to resolve this issue: LookUpEdit - Text disappears after moving focus from the editor.

Issue 2. The display text of a selected record is not displayed or an exception is thrown after you set the EditValue property.

First, please use the following approach to catch exceptions: How to obtain the exception's call stack.

Possible exceptions:

  • System.InvalidCastException: 'Invalid cast from 'System.Int32' to 'System.Guid'.'
  • System.FormatException: 'Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).'
  • System.InvalidCastException: 'Object must implement IConvertible.'
  • System.IndexOutOfRangeException: 'Index was outside the bounds of the array.'
  • DevExpress.Data.Helpers.InconsistencyDetectedException : 'Key 'X' fetched at index 'Y' does not match previously fetched key 'Z' for the same index'

Usually, the exception originates in the DevExpress.Data.DataColumnInfo.ConvertValue method and the call-stack looks as follows:

Call Stack
System.dll!System.ComponentModel.GuidConverter.ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) Unknown DevExpress.Data.v20.1.dll!DevExpress.Data.DataColumnInfo.ConvertValue(object val, bool useCurrentCulture, DevExpress.Data.DataControllerBase controller) Unknown DevExpress.Data.v20.1.dll!DevExpress.Data.DataController.FindRowByValueCore(object value, DevExpress.Data.DataColumnInfo column, int startIndex, int count) Unknown DevExpress.Data.v20.1.dll!DevExpress.Data.DataController.FindRowByValue(string columnName, object value, DevExpress.Data.OperationCompleted[] completed) Unknown DevExpress.Data.v20.1.dll!DevExpress.Data.GridLookupDataController.FindRowByValue(string columnName, object value, DevExpress.Data.OperationCompleted[] completed) Unknown DevExpress.XtraGrid.v20.1.dll!DevExpress.XtraEditors.Repository.RepositoryItemGridLookUpEditBase.GetIndexByKeyValueCore(object keyValue, DevExpress.Data.OperationCompleted[] completed) Unknown

If you are using GridLookUpEdit or SearchLookUpEdit in Server Mode, the issue may occur due to InconsistencyDetectedException. The InconsistencyDetected exception is thrown when an inconsistency has been detected during an operation on a data source. The exception message describes what happened in your case. The exception may occur if the KeyExpression property of your data source is set to a field that contains non-unique values. Make sure that you set KeyExpression to a unique field or the primary key field.

Solution: Check that the following is true. Your lookup data source contains records. The ValueMember property is set to a key column name. The control's EditValue property is set to a value that exists in the key column. The data type of the key column matches the data type of the assigned value.

Consider the following example. You have a string field in your data source and assign ValueMember to this field:

C#
DataTable table = new DataTable(); table.Columns.Add("Id", typeof(string)); lookUpEdit.Properties.ValueMember = "Id";
Visual Basic
Dim table As New DataTable() table.Columns.Add("Id", GetType(String)) lookUpEdit.Properties.ValueMember = "Id"

An attempt to set the EditValue property to an integer value fails because of data type mismatch:

C#
lookUpEdit.EditValue = 0;
Visual Basic
lookUpEdit.EditValue = 0

Either change the data source field type

C#
table.Columns.Add("Id", typeof(int));
Visual Basic
table.Columns.Add("Id", GetType(Integer))

or set EditValue to a string

C#
lookUpEdit.EditValue = "0"
Visual Basic
lookUpEdit.EditValue = "0"

Tip: Set the ThrowExceptionOnInvalidLookUpEditValueType property to True to detect data type conflicts.

Issue 3. A drop-down window is shown behind the lookup editor's owner form in a remote environment (Remote App, etc.).

Solution: Set the static global DevExpress.XtraEditors.Popup.PopupBaseForm.ForceRemotingCompatibilityMode property to true:

C#
DevExpress.XtraEditors.Popup.PopupBaseForm.ForceRemotingCompatibilityMode = true;
Visual Basic
DevExpress.XtraEditors.Popup.PopupBaseForm.ForceRemotingCompatibilityMode = True

Tip: This solution works for all components that have a drop-down window. See Item selectors.

The issue is not on the Known Issues list:

If the issue you are facing is not described above, try the following steps to resolve it.

Steps:

  • Look for similar issues, errors and solutions on the web, Stack Overflow or in our Support Center.
  • If you could not find any information about the error, please post a new ticket in our Support Center and share as much information as possible (call stack, steps to reproduce, a project where the issue is reproducible). This information will help us determine the cause of the issue in the fastest and most straightforward way.

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.