views:

1590

answers:

2

This should be a fairly easy task, however I'm a bit stumped, I have a LookUpEdit control, I have databound it to a datasource and set the displaymember and ValueMenber correctly.

This control is now correctly populating.

My problem is that normally I would pull some data and then 'set' it to the ID eg:

LookUpEdit.EditValue = [Some ID from my database]

However In this particular case, I do not have access to the ID BUT I do have access to the displymember value (from the database), so how do I set the LookUpEdit control given the displaymember value only?

A: 

Solved it!

If you set it as follows:

LookUpEdit.Text = [String Value from Database]

IF that string value matches exactly, then the editValue (i.e. the ID) is also correctly set to the item you have pulled from the Database.

This property 'Text' seems somewhat illogical (in my view)(for example they have GetDatasourceByName etc, surely it would make sense to have SetItemByName or something similar!), but it works in any case.

Darknight
+4  A: 

Use:

lookUp.EditValue = lookUp.Properties.GetKeyValueByDisplayText(yourDisplayText);

It is preferred way. Using Text property is a bit illogical as you noted. It works now, but I wouldn't be surprised if it stops working in the future after you upgrade DevExpress assemblies.

Przemaas
Yes! thanks that makes mush more sense.
Darknight
sorry typo: 'much'
Darknight