Click here to Skip to main content
15,892,697 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi iam using c#.net windows application i need to pass values to textboxes in another form on double click of datagrid rowcell and need to edit and again save to the same grid which is another form
Posted
Comments
Sunasara Imdadhusen 2-Dec-10 0:02am    
You should try yourself, if you are stuck anywhere in code then ask for help.

Hi Narendra,

Follow this steps it may help you.

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


2.Open form2 like this

C#
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 variable.
C#
private void button1_Click(object sender, EventArgs e)
       {
           strvalue = textBox1.Text;
           this.Close();
       }
 
Share this answer
 
Comments
narendra999 2-Dec-10 2:12am    
thanks for helping me...its working
Hope this will help you,

C#
private void GetValueFromDGVToTextBox()
        {
            int row = this.dataGridView1.CurrentCell.RowIndex;
            if (row > -1)
            {
                string value = this.dataGridView1[1, row].FormattedValue.ToString();
                textBox1.Text = value;
            }
        }
 
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