C# 在datagridview的文本框中显示数据

C# 在datagridview的文本框中显示数据,c#,C#,我的windows窗体应用程序C中有两个文本框和一个datagridview工具, 我想,如果用户单击datagridview中的任何一行,这一行中的数据应该显示在tow文本框中 我怎么能做这件事 谢谢大家 描述 您可以订阅DataGridView CellClick事件 样品 更多信息 // subscribe the event using code yourDataGridView.CellClick += new DataGridViewCellEventHandler(YourGrid

我的windows窗体应用程序C中有两个文本框和一个datagridview工具, 我想,如果用户单击datagridview中的任何一行,这一行中的数据应该显示在tow文本框中 我怎么能做这件事

谢谢大家

描述 您可以订阅DataGridView CellClick事件

样品 更多信息
// subscribe the event using code
yourDataGridView.CellClick += new DataGridViewCellEventHandler(YourGridView_CellClick);

// handle the event
private void YourGridView_CellClick(object sender,
    DataGridViewCellEventArgs e)
{
    DataGridViewImageCell cell = (DataGridViewImageCell)
        yourDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex];

   yourTextBox.Text = cell.Value;
}