c# - Selected Index Change Calling when Filling values in Combobox -
in below code have combobox
. when try fill values in combobox
, on loading calling selectedindexchanged
without selecting value combobox
.
public void bindcombobox() { software pd = new software(); dataset dsproj = pd.userid(); cbvalue.datasource = dsproj.tables[0];//calling selectedindexchanged cbvalue.displaymember = "projectname"; cbvalue.valuemember = "projectid"; } private void cbvalue_selectedindexchanged(object sender, eventargs e) { }
i guess must use boolean variable. may , used method avoid problem given below.
1) declare boolean valiable global scope, set false. 2) before binding combobox set boolean=false
, , after binding has been completed set boolean=true
. 2) on first line of combobox_selectionchangeevent
, check condition boolean true or false. if true rest of things.
like this..
boolean flag=false public void bindcombobox() { software pd = new software(); dataset dsproj = pd.userid(); flag=false; cbvalue.datasource = dsproj.tables[0];//calling selectedindexchange cbvalue.displaymember = "projectname"; cbvalue.valuemember = "projectid"; flag=true; } private void cbvalue_selectedindexchanged(object sender, eventargs e) { if(flag==true) { ... //rest of code } }
Comments
Post a Comment