Click here to Skip to main content
15,939,065 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Everyone. I need you help. I have a two form. there is a Datagridview in Form1 and there is 5 units textbox in Form2. My question is: when i selected cell click in datagridview, How to Pass Values Form2 textboxes

Posted
Updated 19-Nov-13 5:04am
v4

Hi, try making some resarch before posting questions!

Passing Data Between Forms[^]

Good luck
 
Share this answer
 
Comments
Maciej Los 19-Nov-13 14:37pm    
+5!
Good link!
C#
public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            dataGridView1.Rows.Add( 1,2);
        }
        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == -1 )
            {
                try
                {
                    Form2 f2 = new Form2();
                    f2.dgvr = dataGridView1.Rows[e.RowIndex];
                    f2.Show();
                }
                catch (Exception er)
                {
                    MessageBox.Show(er.Message.ToString());
                }
            }
        }
    }

C#
public partial class Form2 : Form
    {
        public DataGridViewRow dgvr;
        public Form2()
        {
            InitializeComponent();
        }
        private void Form2_Load(object sender, EventArgs e)
        {
            textBox1.Text = dgvr.Cells[0].Value.ToString();
            textBox2.Text = dgvr.Cells[1].Value.ToString();
        }
    }
 
Share this answer
 
Comments
123ugur 20-Nov-13 2:08am    
T-Maz thanks for help but I have an error "No row can be added to a DataGridView control that does not have columns. Columns must be added first."
can you help me for this error.

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