Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DataGridView selected row to display in text boxes

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.

Get Selected Row to text boxes

like image 609
Matt List Avatar asked Apr 28 '15 02:04

Matt List


People also ask

How do I pass DataGridView selected row value to TextBox?

Text = Convert. ToString(frm. DataGridView1[1, row]. Value);

How can we get selected row data from GridView in ASP NET?

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.


1 Answers

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;
}
like image 120
Iswanto San Avatar answered Oct 13 '22 13:10

Iswanto San