Click here to Skip to main content
15,885,141 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am using combobox and checkboxlist in my windows form and its values are same. I am facing one issue while change the selected value of these controls. If I changing selected value in the checkboxlist, then the combobox selected value is also changed as the same in the checkboxlist and viceversa. I need to restrict this. Please help me.
Posted
Comments
Orcun Iyigun 27-May-13 7:01am    
Did you bind their selectedindexchanged event to the same event? Also it would be helpful if you can provide some code
blessy baby 28-May-13 0:04am    
I didn't write any code in selectedindexchanged event. only bind these controls with same datasource

DataTable dtAgencies = GetAgencies();
if (dtAgencies.Rows.Count > 0)
{
this.chkListChild.DataSource = dtAgencies;
this.chkListChild.DisplayMember = "agencyID";
this.chkListChild.ValueMember = "conString";

this.cmbParent.DataSource= dtAgencies;
this.cmbParent.DisplayMember = "agencyID";
this.cmbParent.ValueMember = "conString";

}
Mayur Panchal 27-May-13 7:05am    
Have you bind both controls with same datasource ?
blessy baby 28-May-13 0:03am    
Yes. bind with the same source
Sunasara Imdadhusen 27-May-13 7:56am    
Exactly you have bounded both controls event with single.

Try below code:

DataTable dtAgencies = GetAgencies();
if (dtAgencies.Rows.Count > 0)
{
      this.chkListChild.DataSource = dtAgencies;
      this.chkListChild.DisplayMember = "agencyID";
      this.chkListChild.ValueMember = "conString";
      
      DataTable dtCopy = dtAgencies.Copy();             
      this.cmbParent.DataSource= dtCopy;
      this.cmbParent.DisplayMember = "agencyID";
      this.cmbParent.ValueMember = "conString";
              
}


Hope it helps!
 
Share this answer
 
Comments
Renju Vinod 28-May-13 7:29am    
+5
Using a dtAgencies.Copy() is a good idea. chkListChild and cmbParent should be bound different
 
Share this answer
 
you should add extra if condition to control this...
combobox selected index change event...
C#
if (YourComboboxName.Focused == true)
{
 //checkbox selection-index code here 
}


Checklistbox selected index change event...
C#
if (YourChecklistboxName.Focused == true)
{
 //Combobox selection-index code here 
}

Happy Coding!
:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900