Click here to Skip to main content
15,886,963 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Guys help me with this problem
I have two form Form1 contains Four ComboBox and Form2 contain one ComboBox and one Datagridview with three column.

When I mouseclick on One ComboBox in Form1 it displays Form1 and fill ComboBox that come from ComboBox (Form1) and fill DataGridView info that related to that ComboBox(Form2). So, When I click on one row in DataGridView (in Form2), the data from that row it passing to other three ComboBox in Form1.

When I do mouseclick on ComboBox in (Form1) it passing data to ComboBox in (Form2) and display the rows in DataGridview that related to ComboBox in (Form2), correctly. However, When I mouseclick on one row it does not pass that from DataGridView in (Form2) to three ComboBox in (Form1).

Please, I need your help.


What I have tried:

This is in Form1.
Display Form2 and Pass data to ComboBox (Form1)

<pre>private void ComboBox1_MouseClick(object sender, MouseEventArgs e)
        {
            Form2 f2 = new Form2(this.ComboBox.Text);
            f2.MdiParent = this.MdiParent;
            f2.Show();
        }


this Function it return the Data from DataGridView (Form2) to Form1
public Form1(string Data1, string Data2, string Data3)
        {
            InitializeComponent();
            this.ComboBox1.Text = Data1;
            this.ComboBox2.Text = Data2;
            this.ComboBox3.Text = Data3
            this.ActiveControl = this.ComboBox1;
        }

=======================================
In Form 2 this is Code:
Get data from Form1
public Form2(string Data1)
        {
            InitializeComponent();
            this.ComboBox.Text = Data1;
        }


This is when I send data to Form1
private void DataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            Form1 F1 = new Form1(this.DataGridView1.CurrentRow.Cells[0].Value.ToString(),
                this.DataGridView1.CurrentRow.Cells[1].Value.ToString(), this.DataGridView1.CurrentRow.Cells[2].Value.ToString(),
        }
Posted
Updated 13-Nov-18 4:09am

1 solution

You are creating new instances all the time - that's not what you need to do at all.
See here: Transferring information between two forms, Part 2: Child to Parent[^]

The other two may be of use as well:
Transferring information between two forms, Part 1: Parent to Child[^]
Transferring information between two forms, Part 3: Child to Child[^]
 
Share this answer
 
Comments
OriginalGriff 13-Nov-18 11:20am    
Exactly the same way ... you just have to write an appropriate property.
Karam Ibrahim 13-Nov-18 11:33am    
thanks Dear OriginalGiff, I got what you mention now I will change my code thank you again the problem has been solved. Regards.
OriginalGriff 13-Nov-18 11:42am    
You're welcome!

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