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
Posted by Abys, Love:
I've correctly specified the DisplayMember and ValueMember properties. But, the problem still persists.
Hi,
To find the exact cause of this issue, we need a small sample that shows it. For this, I have created a separate ticket (Q286900). We will discuss this shortcoming there.
I had the same problem, only to find out that my column names specified in the data source was in a different case than specified in my project.
I found as above… the Datasource column name had to match up with what the gridview column name was. So in my case the relevant datatable column name has to be the same as the relevant gridview column name.
Also… I was using a list as the lookupedit datasource and didn't have to set the Displaymember or Valuemember.
Hi,
It seems that you have resolved the issue. Note that the column name in the data source should be equal to the GridColumn.FieldName property.
I did a big project, using 11.2, and I use a lot of xtragrid controls, with loopkups wich worked just fine. I migrate my project to Vn 12,2, It was a mess, I have to rebuild my project from scratch, but I can´t make lookupedit work as before.
Hello,
In order not to mix several questions within one thread, I will extract your question to a new ticket. Let us continue our discussion there LookUpEdit - After migration to 12.2 it does not works correctly.
Why your f…ing lookupedit does not preserve text. VS own combobox does it well.
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.
Thats pretty bad s…y design.
When the control loses focus the text in the cotrol's text box should not be removed.
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.