Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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


I have two windows form
Form1 (have combobox1 drop down style:drop down list)
Edir Row (I have combobox and button)



Details

form1_load

C#
var dataSourceAr = new List<Country>();
 dataSourceAr.Add(new Country() { Name = "اختر دوله", Value = 0 });
 dataSourceAr.Add(new Country() { Name = "الاردن", Value = 1 });
 var dataSourceEn = new List<Country>();
 dataSourceEn.Add(new Country() { Name = "SelectCountry", Value = 0 });
 dataSourceEn.Add(new Country() { Name = "Jordon", Value = 1 });
 var combined = dataSourceEn.Join(dataSourceAr, en => en.Value, ar => ar.Value, (en, ar) => new { Value = en.Value, Name = $"{ar.Name} - {en.Name}" }).ToList();
 comboBox1.DataSource = combined;
 comboBox1.DisplayMember = "Name";
 comboBox1.ValueMember = "Value";

public class Country
    {
        public string Name { get; set; }
        public int Value { get; set; }
    }


under button 1 click on windows form Edit Row that i need to pass selected value from it to form1 combobox

C#
private void button1_Click(object sender, EventArgs e)
        {  
                Form1 frm = new Form1();
                var cb1 = frm.comboBox1;
                var index1 = cb1.FindString(comboBox1.Text);
                cb1.Text = index1.ToString();
                frm.Show();




                
            
        }


C#
Edit Row load form
// same values and code of  combobox1 in Form1


when click button value of combobox1 from Edit form will transfere to second form Form1

Result of code above

when click button it show form1 but no selection to combobox on form1 as Edit Row form
So that what i do to solve problem ?

What I have tried:

How to pass combobox value from windows form EdirRow to windows form Form1 where click button
Posted
Updated 12-Mar-17 1:02am
Comments
[no name] 12-Mar-17 6:43am    

1 solution

It sounds complex, but it's pretty simple when you get your head around it: Transferring information between two forms, Part 2: Child to Parent[^] - in your case, Form1 is the "Parent", and "Edirrow" is the child.
 
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