0

我有一个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";
        }

我的查找编辑有 3 个元素,如下所示。

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

我尝试设置如下选择

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

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

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

这些尝试无法在lookupedit 中设置选择。请帮我

4

1 回答 1

1

你必须匹配类型。如果LOGICALREF是类型int而不是您的呼叫是:

lookUpEditGeldigiFirma.EditValue = 2;
于 2013-07-13T02:38:17.107 回答