This code should do that. Add this method as the event handler for the
"KeyDown" event of the datagridview.
private void dataGridView1_KeyDown(object sender,
KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
if ((dataGridView1.SelectedRows.Count > 0))
{
DataGridViewRow r = dataGridView1.SelectedRows[0];
StringBuilder s = new StringBuilder();
foreach (DataGridViewCell cell in r.Cells)
{
s.Append(cell.Value);
s.Append(",");
}
s.Remove(s.Length - 1, 1);
textBox1.Text = s.ToString();
}
}
}
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.