Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I work in windows form c# vs 2015

I have two combo box for country Arabic and county English

I need if user select value from combo box 1 select same value from combo box 2

my user permanent forget and select wrong country for combo box 2

my code as below :

C#
var dataSourceAr = new List<Country>();
            dataSourceAr.Add(new Country() { Name = "اختر دوله", Value = 0 });
            dataSourceAr.Add(new Country() { Name = "الاردن", Value = 1 });
            dataSourceAr.Add(new Country() { Name = "الإمارات", Value = 2 });
            dataSourceAr.Add(new Country() { Name = "السعوديه", Value = 3 });
            dataSourceAr.Add(new Country() { Name = "البحرين", Value = 4 });
            dataSourceAr.Add(new Country() { Name = "تونس", Value = 5 });
           
            this.comboBox2.DataSource = dataSourceAr;
            this.comboBox2.DisplayMember = "Name";
            this.comboBox2.ValueMember = "Value";

 var dataSourceEn = new List<Country>();
            dataSourceEn.Add(new Country() { Name = "SelectCountry", Value = 0 });
            dataSourceEn.Add(new Country() { Name = "Jordon", Value = 1 });
            dataSourceEn.Add(new Country() { Name = "Emarate", Value = 2 });
            dataSourceEn.Add(new Country() { Name = "Saudia", Value = 3 });
            dataSourceEn.Add(new Country() { Name = "Bahreen", Value = 4 });
            dataSourceEn.Add(new Country() { Name = "Tunisi", Value = 5 });
           


            comboBox1.DataSource = dataSourceEn;
            comboBox1.DisplayMember = "Name";
            comboBox1.ValueMember = "Value";
public class Country
    {
        public string Name { get; set; }
        public int Value { get; set; }
    }

so that i need if user select value 1 from combo box 1 automatic select value 1 from combo box 2

i need to force him to get same value in two combo box

IF HE select value 3 from com box 1 select value 3 from comb box 3

How to do that if possible ?

What I have tried:

How to make two combo box with same selected value
Posted
Updated 7-Feb-17 1:49am
Comments
ZurdoDev 7-Feb-17 7:19am    
Something simple like this should work.
Combox1.SelectedIndex = Combox1.FindStringExact("someString")

1 solution

Add SelectedIndexChanged event to the dataSourceAr combobox
private void dataSourceAr_SelectedIndexChanged(object sender, EventArgs e)
      {
          this.dataSourceEn.SelectedIndex = (sender as ComboBox).SelectedIndex;
      }
 
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