Hello so I managed to get the row where my mouse highlighted it. However I don't know how to access its content.
for example: I highlighted row 25 I can get that it highlighted row 25 howver I don't know how to access its content and put it all in a textbox. anyone?
you can use the value property to access the content of the cell as follows
// the content of the cell
var x = dataGridView1.Rows[0].Cells[0].Value;
// this gets the content of the first selected cell
dataGridView1.SelectedCells[0].Value;
// you can set the cells the user is able to select using this
dataGridView1.SelectionMode= SelectionMode. //intellisense gives you some options here
To do exactly what you are asking something like this should suffice
System.Text.StringBuilder t = new System.Text.StringBuilder();
String delimiter = ",";
foreach(DataGridViewCell c in dataGridView1.SelectedRows[0].Cells)
{
t.Append(c.Value);
t.Append(delimiter);
}
textBox1.Text = t.ToString();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With