Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set the Selected value on a DevExpress LookupEdit?

Tags:

devexpress

I previously asked a similar question, but the code was much more complicated. This question involves a similar problem, but the code is drastically simplified. Still, even as simple as this example is, I can NOT get the dropdown to pre-select the correct value.

I have a dropdown that is populated w/ values correctly. Also, when I change the dropdown to any of the values, and then save my form, the database record is updated w/ the correct value. That much is working, but selecting the correct value on form load 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 set either of these during form load, nothing happens; the dropdown has a blank entry selected (and the rest of the values are seen when you expand the dropdown). I've tried each of these methods:

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

Edit - I posted a comment below under platon's answer, but I'll post it here as well. I eventually used a stored procedure instead to populate this dropdown, instead of an Enum. From that point on, the dropdown loaded w/ the correct selected value.

like image 939
WEFX Avatar asked Mar 01 '13 20:03

WEFX


People also ask

How do I get the selected value in LookUpEdit DevExpress?

Answers approved by DevExpress Supportobject obj = lookUpEdit. EditValue; string text = lookUpEdit. Text; Note, the LookUpEdit.


1 Answers

You need to set the editor's EditValue property to a value according to the type of the editor's Properties.ValueMember field type. I mean, if this is a string field, the EditValue should be set to "2", not 2 and so on. This should help. If not, please try to call the editor's Properties.ForceInitialize() method after you've set the editor's DataSource property.

like image 55
platon Avatar answered Sep 28 '22 06:09

platon