ahmed salah

ahmed salah

  • NA
  • 85
  • 59k

How to pass combobox value from EdirRow form to form1

Mar 12 2017 6:17 AM
Actually i need when click on button 1 on windows form Edit Row
get selected value of combobox1 from windows form Edit Row
to windows form Form1 .
 
Details
 
I have two windows form
 
Form1
 
Edir Row
 
in form1 i have combobox1 drop down style:drop down list
 
form1_load
 
  1. var dataSourceAr = new List<Country>();  
  2. dataSourceAr.Add(new Country() { Name = "???? ????", Value = 0 });  
  3. dataSourceAr.Add(new Country() { Name = "??????", Value = 1 });  
  4. dataSourceAr.Add(new Country() { Name = "????????", Value = 2 });  
  5. var dataSourceEn = new List<Country>();  
  6. dataSourceEn.Add(new Country() { Name = "SelectCountry", Value = 0 });  
  7. dataSourceEn.Add(new Country() { Name = "Jordon", Value = 1 });  
  8. dataSourceEn.Add(new Country() { Name = "Emarate ", Value = 2 });  
  9. var combined = dataSourceEn.Join(dataSourceAr, en => en.Value, ar => ar.Value, (en, ar) => new { Value = en.Value, Name = $"{ar.Name} - {en.Name}" }).ToList();  
  10. comboBox1.DataSource = combined;  
  11. comboBox1.DisplayMember = "Name";  
  12. comboBox1.ValueMember = "Value";  
  1. public class Country  
  2. {  
  3. public string Name { getset; }  
  4. public int Value { getset; }  
  5. }  
under button 1 click on windows form Edit Row that i need to pass selected value from it to form1 combobox
 
  1. private void button1_Click(object sender, EventArgs e)  
  2. {  
  3. Form1 frm = new Form1();  
  4. var cb1 = frm.comboBox1;  
  5. var index1 = cb1.FindString(comboBox1.Text);  
  6. cb1.Text = index1.ToString();  
  7. frm.Show();  
  8.   
  9.   
  10.   
  11.   
  12. }  
In Edit Row form
I have combobox and button in Edit Row form
when click button value of combobox1 from Edit form will transfere to second form Form1
  1. Edit Row load form  
  2. // same values and code of combobox1 in Form1  
Result of code above :
when click button in Edit Form  it show form1
 
but value of combobox1 selected from Edit Row form not select same value to another combox in form1
 
nothing changed and nothing selected in form1 combobox value
 
so that how to solve problem ?
 

Answers (1)