Click here to Skip to main content
15,896,348 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a form with a datagridview on it. The data is displayed from a database inside the datagridview. On double click of datagridview I want to display complete row on textboxes which are on a new form. How to achieve this?
Posted

1 solution

Follow this steps it may help you.

1. declare a constructor and a public variable in the form which you want to open.
public  string strvalue = string.Empty;
        public Form2()
        {
            InitializeComponent();
        }
        public Form2(string str)
        {
            strvalue = str;
            InitializeComponent();
        }


2.Open form2 like this
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex != -1)
            {
                if (e.ColumnIndex != 1)
                {
                    if (!string.IsNullOrEmpty(dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString()))
                    {
                        string strValue = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
                        Form2 _Form2 = new Form2(strValue);
                        _Form2.ShowDialog();
                        dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = _Form2.strvalue;
                        dataGridView1.Refresh();
                    }
                }
            }
        }

3. Close form2 on a event and set value in
private void button1_Click(object sender, EventArgs e)
       {
           strvalue = textBox1.Text;
           this.Close();
       }
 
Share this answer
 
Comments
Prasad_Kulkarni 23-May-12 9:34am    
Glad it helps!

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