How to get the devexpress lookupedit display text from the corresponding edit value

35,238

Solution 1

You can't, at least not in the way you're trying. The LookUpEdit, as the name implies, looks up its values in a DataSource, eg. a collection of objects. Therefore, to display the value 3 you need to have a list of objects that contains this value and set it as a DataSource for the control.

List<string> values = new List<string>();
values.Add("3");
lookUpEdit.Properties.DataSource = values;
lookUpEdit.EditValue = "3";

Maybe if you specify what are you trying to do, we can help you achieve that.

Solution 2

I think you don't have to specify display member or value member to get your needed behaviour. Following code give me a form with the lookupedit correctly showing "4", and i can choose other values from the list too.

using System.Collections.Generic;
using System.Windows.Forms;
using DevExpress.XtraEditors;

public class Form1 : Form
{
    public Form1()
    {

        var lookUpEdit1 = new LookUpEdit();
        Controls.Add(lookUpEdit1);

        var source = new List<string>();
        for (var i = 0; i < 10;i++ )
            source.Add(i.ToString());
        lookUpEdit1.Properties.DataSource = source;
        lookUpEdit1.EditValue = "4";
    }

}

Maybe you get wrong results because you set display member and value member of the control.

Solution 3

This code worked for me.

private void lookUpEdit1_KeyUp(object sender, KeyEventArgs e)
{
    if (e.Key == Key.Enter)
    {
        MessageBox.Show((e.OriginalSource as SLTextBox).Text);
    }
}
Share:
35,238
Vyasdev Meledath
Author by

Vyasdev Meledath

#SOreadytohelp

Updated on April 19, 2020

Comments

  • Vyasdev Meledath
    Vyasdev Meledath about 4 years

    Hai all,

    I want to get lookupedit display text when am giving correspond edit value.

    example: if am giving

    LookupEdit1.Editvalue="3";
    

    then it should show display text of Editvalue="3"

    please help

    //code

     cmbChemical.Properties.DataSource = _lab.selectChemicals();
            cmbChemical.Properties.DisplayMember = "labitem_Name";
            cmbChemical.Properties.ValueMember = "labItem_ID";
            cmbChemical.Properties.BestFitMode = BestFitMode.BestFit;
            cmbChemical.Properties.SearchMode = SearchMode.AutoComplete;
    
            cmbChemical.Properties.Columns.Add(new LookUpColumnInfo("labitem_Name", 100,  "Chemicals"));
        cmbChemical.Properties.AutoSearchColumnIndex = 1;
    
  • devnull
    devnull over 13 years
    post your entire scenario, what are you binding to that lookupedit and why do you need it to display the value 3
  • Vyasdev Meledath
    Vyasdev Meledath over 13 years
    Problem is that, am already bind both display member and value member of lookupedit, when i give edit value =3 or something then correspond text should be selected in the lookpedit. please help
  • devnull
    devnull over 13 years
    Are you binding on a DataTable? If yes, can you post the structure?
  • Vyasdev Meledath
    Vyasdev Meledath over 13 years
    s am using datatable contain labitem_Name,labItem_ID . I given code above with my question
  • devnull
    devnull over 13 years
    it might be something with labitem_ID datatype. if it's int you should give it the value 3 as int not string.
  • Vyasdev Meledath
    Vyasdev Meledath over 13 years
    I given as you told.but editvalue is not changing.It always shows initial edit value given through property window