lookupedit set selection by value

Arif YILMAZ picture Arif YILMAZ · Jul 12, 2013 · Viewed 12.9k times · Source

I have a lookupedit and I need to set its selection by click event of a button. But I couldnt do it.

this is how I fill the lookupedit

using (SqlConnection conn = new SqlConnection(GlobalParameters.logoSqlConnectionString))
        {
            conn.Open();
            string selectSql = @"SELECT LOGICALREF,DEFINITION_ FROM [LG__CLCARD]";
            DataTable dtDetail = GlobalParameters.getDataTable(selectSql, GlobalParameters.logoSqlConnectionString);
            lookUpEditGeldigiFirma.Properties.DataSource= dtDetail;
            lookUpEditGeldigiFirma.Properties.DisplayMember = "DEFINITION_";
            lookUpEditGeldigiFirma.Properties.NullText = "Lütfen seçiniz.";
            lookUpEditGeldigiFirma.Properties.ValueMember = "LOGICALREF";
        }

my lookupedit has 3 elements like below.

value:1  text:apple
value:2  text:orange
value:3  text:melon

I tried to set the selection like below

// first attempt
lookUpEditGeldigiFirma.EditValue = "2";

// second attempt
lookUpEditGeldigiFirma.Properties.DisplayMember = "orange";

// third attempt
lookUpEditGeldigiFirma.Properties.ValueMember = "2";

these attempts didnt work to set the selection in lookupedit. Please help me

Answer

Brad Rem picture Brad Rem · Jul 13, 2013

You have to match the type. If LOGICALREF is type int than your call is:

lookUpEditGeldigiFirma.EditValue = 2;