Click here to Skip to main content
15,937,602 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When Clicking on a row of a gridview the text box should fill in windows application using c#
Updated 27-Nov-13 18:53pm


Try this code.. In Many ways u can implement it.. this is one of the method..

private void Form1_Load(object sender, EventArgs e)

            DataTable dt = new DataTable();
            dt.Columns.Add("Name", typeof(string));
            dt.Columns.Add("ID", typeof(int));
            dt.Rows.Add("aaaa", 1);
            dt.Rows.Add("bbbb", 2);
            dt.Rows.Add("cccc", 3);
            dt.Rows.Add("ddd", 4);
            dt.Rows.Add("eeee", 5);

            dataGridView1.DataSource = dt;


        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
           textBox1.Text =  dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].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