开发者

Concerned with selectedindexchanged of dropdownlist

I have a combobox in which iam loading combobox using following cod开发者_运维百科e.

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;

        }

Problem is in pCmbCustomer.DataSource = ds.Tables[0];selected indexchanged event of combobox is working.how can i avoid selected indexchanged event while binding combobox?Can anybody help?


You can attach to the SelectedIndexChanged event handler once you've finished binding the combobox.

So instead of attaching the event directly in the user control, attach it in your codebehind either at the end of LoadCustomer1 or outside of it after LoadCustomer1 has been called.


Avoid handling selectedIndexChangedEvent as mush as possible.

Avoid using pCmbCustomer.Text = "--- Select Customer Id ---"; this type of statements. That is, do not set the text explicitly.

Make the text "--- Select Customer Id ---" as a member of the list.

Then use this pCmbCustomer.SelectedIndex = 0,2,3...,n; statement when you need.


I would use the SelectionChangeCommitted instead of using the SelectedIndexChange if possible.

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

"SelectionChangeCommitted is raised only when the user changes the combo box selection. Do not use SelectedIndexChanged or SelectedValueChanged to capture user changes, because those events are also raised when the selection changes programmatically."

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜