WinForms Comboboxes
-
Hi, I have two comboboxes, cbPhysicalCountry and cbPostalCountry. Both Comboboxes are populated via a dataset. How can I set the cbPostalCountry = cbPhysicalCountry when the user checks the checkbox "UsePhysicalCountry"? I populate my comboboxes with the following code
DataSet dsPhysicalCountry = WCFService.GetCountry();
cbPhysicalCountry.DataSource = dsPhysicalCountry.Tables["Country"];
cbPhysicalCountry.DisplayMember = "Country";
cbPhysicalCountry.ValueMember = "Id";When the checkbox_checkchanged event fires I have the following code,
if(checkbox.checked == true)
{
cbPostalCountry.SelectedItem = cbPhysicalCountry.SelectedItem;
}Thank you in advance...
Illegal Operation
-
Hi, I have two comboboxes, cbPhysicalCountry and cbPostalCountry. Both Comboboxes are populated via a dataset. How can I set the cbPostalCountry = cbPhysicalCountry when the user checks the checkbox "UsePhysicalCountry"? I populate my comboboxes with the following code
DataSet dsPhysicalCountry = WCFService.GetCountry();
cbPhysicalCountry.DataSource = dsPhysicalCountry.Tables["Country"];
cbPhysicalCountry.DisplayMember = "Country";
cbPhysicalCountry.ValueMember = "Id";When the checkbox_checkchanged event fires I have the following code,
if(checkbox.checked == true)
{
cbPostalCountry.SelectedItem = cbPhysicalCountry.SelectedItem;
}Thank you in advance...
Illegal Operation
try this way, if (checkBox1.Checked == true) cbPostalCountry.SelectedValue= cbPhysicalCountry.SelectedValue;
-
Hi, I have two comboboxes, cbPhysicalCountry and cbPostalCountry. Both Comboboxes are populated via a dataset. How can I set the cbPostalCountry = cbPhysicalCountry when the user checks the checkbox "UsePhysicalCountry"? I populate my comboboxes with the following code
DataSet dsPhysicalCountry = WCFService.GetCountry();
cbPhysicalCountry.DataSource = dsPhysicalCountry.Tables["Country"];
cbPhysicalCountry.DisplayMember = "Country";
cbPhysicalCountry.ValueMember = "Id";When the checkbox_checkchanged event fires I have the following code,
if(checkbox.checked == true)
{
cbPostalCountry.SelectedItem = cbPhysicalCountry.SelectedItem;
}Thank you in advance...
Illegal Operation
What happens if the postal and physical countries are different? Try SelectedValue instead of item. Try using a BindingSource instead of a table.
Never underestimate the power of human stupidity RAH