views:

301

answers:

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;
+1  A: 

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
post your entire scenario, what are you binding to that lookupedit and why do you need it to display the value `3`
devnull
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
Vyas
Are you binding on a `DataTable`? If yes, can you post the structure?
devnull
s am using datatable contain labitem_Name,labItem_ID .I given code above with my question
Vyas
it might be something with `labitem_ID` datatype. if it's int you should give it the value 3 as int not string.
devnull
I given as you told.but editvalue is not changing.It always shows initial edit value given through property window
Vyas
+1  A: 

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