How to set Selected value to DevExpress LookupEdit?

I asked a similar question earlier, but the code was much more complicated. This question has a similar problem, but the code is greatly simplified. However, even as simple as this example, I can’t get a drop-down menu to pre-select the correct value.

I have a dropdown that is correctly populated with w / values. In addition, when I change the drop-down menu to any of the values ​​and then save my form, the database record is updated with the correct value. This works a lot, but choosing the right value when loading the form will not work.

I put these lines in my save method, just to see what I'm working with.

var test1 = _myLookupEdit.EditValue;  //evaluates to 2
var test2 = _myLookupEdit.Properties.KeyValue;  //evaluates to 2

However, when I install any of them while the form is loading, nothing happens; a blank entry is selected in the drop-down list (and the remaining values ​​are displayed when expanding the drop-down list). I tried each of these methods:

_myLookupEdit.EditValue = 2;
_myLookupEdit.Properties.KeyValue = 2;

Edit - I wrote a comment below under Platon's answer, but I will also post it here. In the end, I used the stored procedure to populate this drop-down menu, not Enum. From this moment, the dropdown menu will load with the correct value selected.

+5
source share
1 answer

EditValue Properties. ValueMember. , , EditValue "2", 2 . . , Properties.ForceInitialize() , DataSource .

+10

All Articles