2

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;
Vyasdev Meledath
  • 8,926
  • 20
  • 48
  • 68

3 Answers3

3

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.

devnull
  • 2,790
  • 22
  • 25
  • post your entire scenario, what are you binding to that lookupedit and why do you need it to display the value `3` – devnull Sep 18 '10 at 09:34
  • 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 – Vyasdev Meledath Sep 18 '10 at 10:14
  • Are you binding on a `DataTable`? If yes, can you post the structure? – devnull Sep 18 '10 at 10:29
  • s am using datatable contain labitem_Name,labItem_ID . I given code above with my question – Vyasdev Meledath Sep 20 '10 at 04:57
  • it might be something with `labitem_ID` datatype. if it's int you should give it the value 3 as int not string. – devnull Sep 20 '10 at 13:44
  • I given as you told.but editvalue is not changing.It always shows initial edit value given through property window – Vyasdev Meledath Sep 21 '10 at 05:01
1

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);
    }
}
Kemal Fadillah
  • 9,760
  • 3
  • 45
  • 63
1

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.

Andrea Parodi
  • 5,534
  • 27
  • 46