首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >关注dropdownlist的selectedindexchanged

关注dropdownlist的selectedindexchanged
EN

Stack Overflow用户
提问于 2009-12-22 18:33:14
回答 3查看 373关注 0票数 0

我有一个combobox,其中我使用以下代码加载combobox。

代码语言:javascript
复制
public void LoadCustomer1(ComboBox pCmbCustomer)
        {
            obj._dtInputParameter.Clear();
            obj.AddInputParameter("@Prm_OpFlag", "S", "String", 1);
            //obj.strSPName = "prc_CUST_Details";
            obj.strSPName = "EditCustCombo";
            DataSet ds = obj.SqlExecuteFill();
            pCmbCustomer.DataSource = ds.Tables[0];
            pCmbCustomer.DisplayMember = "CustomerId";
            pCmbCustomer.ValueMember = "CustomerId";
            pCmbCustomer.Text = "--- Select Customer Id ---";
            pCmbCustomer.SelectedIndex = 0;

        }

问题出在combobox的pCmbCustomer.DataSource = ds.Tables;selected indexchanged事件是否为working.how我可以在绑定combobox时避免选择indexchanged事件吗?有谁可以帮助我吗?

EN

回答 3

Stack Overflow用户

发布于 2009-12-22 18:39:39

一旦完成了组合框的绑定,就可以附加到SelectedIndexChanged事件处理程序。

因此,与其直接将事件附加到用户控件中,不如在调用LoadCustomer1后将其附加到LoadCustomer1的末尾或外部。

票数 1
EN

Stack Overflow用户

发布于 2009-12-22 19:33:30

尽量避免处理selectedIndexChangedEvent

避免使用pCmbCustomer.Text = "--- Select Customer Id ---";这种类型的语句。也就是说,不要显式设置文本。

将文本设置为"--- Select Customer Id ---"作为列表的成员。

然后在需要时使用此pCmbCustomer.SelectedIndex = 0,2,3...,n;语句。

票数 1
EN

Stack Overflow用户

发布于 2009-12-24 22:50:12

如果可能的话,我会使用SelectionChangeCommitted而不是SelectedIndexChange。

MSDN :http://msdn.microsoft.com/en-us/library/system.windows.forms.combobox.selectionchangecommitted.aspx

“仅当用户更改组合框选择时才引发SelectionChangeCommitted。请勿使用SelectedIndexChanged或SelectedValueChanged捕获用户更改,,因为当选择以编程方式更改为时也会引发这些事件。”

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1945505

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档