I have a DataGridView
(tblLoggedJobs) that displays a list of jobs logged by a user. I need the admins to be able to update these jobs to display any updates to the job or note if the job is closed.
I would like the program to display the data in the selected ROW to the textboxes to the right, however I'm not sure how to get this data and display it based on the row that is selected.
Text = Convert. ToString(frm. DataGridView1[1, row]. Value);
When a row is selected in a GridView control, use the SelectedRow property to retrieve the GridViewRow object that represents that row. This is the same as retrieving the GridViewRow object at the index specified by the SelectedIndex property from the Rows collection.
You can use SelectedRows property.
Example:
if(dataGridView1.SelectedRows.Count > 0) // make sure user select at least 1 row
{
string jobId = dataGridView1.SelectedRows[0].Cells[0].Value + string.Empty;
string userId = dataGridView1.SelectedRows[0].Cells[2].Value + string.Empty;
txtJobId.Text = jobId;
txtUserId.Text = userId;
}
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