Click here to Skip to main content
16,012,173 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I wrote the following code to get cell value to textbox..... but it doesn't work,
Please help me to ahead....

private void stdView_CellClick_1(object sender, DataGridViewCellEventArgs e)
{
try
{
rowIndex = e.RowIndex;
DataGridViewRow datarow = stdView.Rows[rowIndex];
id1 = int.Parse(datarow.Cells[0].Value.ToString());
txtName.Text = datarow.Cells[1].Value.ToString();
txtSem.Text = datarow.Cells[2].Value.ToString();
txtDept.Text = datarow.Cells[3].Value.ToString();
txtGdName.Text = datarow.Cells[4].Value.ToString();
txtGdNo.Text = datarow.Cells[5].Value.ToString();
}
catch
{

}
}

Thanks in Advance.........
Posted

1 solution

Try

dataGridView1.Rows[e.RowIndex].Cells["ColumnName"].Value
//Column index can also be used.
 
Share this answer
 
Comments
nest101234 24-Mar-14 3:43am    
I need more clear answer as I'm beginner in C#
JoCodes 24-Mar-14 3:47am    
dataGridView1.Rows[e.RowIndex].Cells["ColumnName"].Value//
Here dataGridView1 is your Grid Control ID, Rows represents the Gridview DataRow RowIndex is the Row of the Gridview ( Index will be fetched as per the Cell Click event is fired) And Cells["ColumnName"] is to Fetch the Cell According to the Column name of the Gridview. Please ask specifically what you are not clear with .

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