KB Article A1023
Visible to All Users

LookUpEdit - Text disappears after moving focus from the editor

Some columns in my Grid Control, TreeList or Vertical Grid are associated with the RepositoryItemLookUpEdit, RepositoryItemGridLookUpEdit, RepositoryItemSearchLookUpEdit or RepositoryItemTreeListLookUpEdit. When I select a value from a lookup list in column A, the value is displayed. But when I change focus to another column (column B), the cell becomes empty. If I return to column A, the original text reappears. How to make sure that the text displayed does not disappear when focus is moved from a lookup column?

Editors affected by the issue:
LookUpEdit, GridLookUpEdit, SearchLookUpEdit, TreeListLookUpEdit

Possible causes of the issue:

The DataSource property is not set

The LookUpEdit control is intended to display a value from a data source and show all possible values in its dropdown. If there is no data source, the editor can’t find a corresponding value and display it. Make sure that the RepositoryItemLookUpEdit.DataSource (LookUpEdit.Properties.DataSource) property is set to a valid source.
Please note that if you use LookUpEdit in in-place mode, the DataSource property should be set for the same RepositoryItem instance as the one you assigned to the ColumnEdit property. If you need to assign different data sources to different cells, handle the GridView.CustomRowCellEdit event and assign different RepositoryItem instances with different data sources to e.RepositoryItem
Grid - How to use LookUp editors with different sources within a single column via the CustomRowCellEdit event
LookUpEdit - Dictionary<> data source.

The data source doesn’t contain a specified value

When you set an editor value or a grid cell value (if the editor is in in-place mode), the editor searches for this value in the data source and displays it in case the operation was successful. If this value is not present in the data source, the editor will display nothing.

The ValueMember property is not set

The RepositoryItemLookUpEdit.ValueMember property specifies a data source field that will be used to find an editor value in the data source. For example, if the data source contains the ID(int) and Name(string) fields, you can set ValueMember to ID and assign 0 to the editor’s/grid cell’s value. In this case, the editor will loop through the data source, find a record with ID = 0, and display its value from the field specified by the DisplayMember property.

A value doesn’t match the ValueMember type / the data source doesn’t contain a record with such a ValueMember value

Let’s suppose that the editor data source contains the ID(int) and Name(string) fields. The ID field is ValueMember and the Name field is DisplayMember. You assign the “0” string value to an editor/grid cell. This value cannot be displayed since the ID column contains int values, and the editor can’t find a record that contains the “0” string value in the ID field. The same issue occurs when the data source is represented by a list of objects and you assign the whole object to the editor value while ValueMember is specified. You can make certain that the lookup editor is properly configured by setting the ThrowExceptionOnInvalidLookUpEditValueType property to true and testing your application. If an exception is thrown when you select a lookup value, the ValueMember field and the editor's underlying value are of different types.

See Also:
LookUpEdit Class
How to filter a second LookUp column based on a first LookUp column's value
How to force the Grid to refresh the values displayed in a LookUp column after loading data
How to Bind an XPCollection to a LookUp

Show previous comments (8)
DevExpress Support Team 9 years ago

    The current version of our LookUp has the AcceptEditorTextAsNewValue property that you can use to make it behave like the default ComboBox. For older versions, we provide the How to make a Lookup editor function as a regular ComboBox code sample that allows accomplishing this task.

    SF SF
    steve frierdich 3 years ago

      Thats pretty bad s…y design.
      When the control loses focus the text in the cotrol's text box should not be removed.

      DevExpress Support Team 3 years ago

        Hello Steve,

        It's not clear to me what this has to do with this article's subject. When an editor is placed in a grid, its value may be discarded due to multiple factors, including the incompatibility of this value with the grid's source. This is not about design, but about a specific implementation.

        If you are talking about a standalone editor, it is possible that you've chosen an inappropriate editor type. Please create a separate ticket and describe your requirements so we can assist you further.

        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.