mms_master
asked on
DataGridView - get value from cell 0 in selected row.
Hi,
I want to get the value from the first cell (i.e. index 0) in the selected row of a DataGridView. The code Im using at the moment is:
dgvCurrentJobs.CurrentRow. Cells(0).V alue.ToStr ing
I've also tried:
dgvCurrentJobs.SelectedRow s.Item(0). Cells(0).V alue.ToStr ing
Both of the above work in respect of returning a value from cell 0. But, no matter which row I select, when this line of code is run, it deselects my selection, selects the first row (Index 0) and returns the value in cell 0 of that row, and not the one I had selected. If that makes sense.
Example:
Column 0 | Column 1
-------------------------- -
R0C0 | R0C1
R1C0 | R1C1
R2C0 | R2C1
If the table above is my DataGridView, and I select the second row which contains "R1C0" in column index 0 and "R1C1" in column index 1; When I press the button that runs the code I mentioned above, the first row containing "R0C0" and "R0C1" becomes highlighted and the value in my msgbox is "R0C0".
Not sure how easy to understand that is, let me know if you cant understand it.
Thanks in advance
mms_master
I want to get the value from the first cell (i.e. index 0) in the selected row of a DataGridView. The code Im using at the moment is:
dgvCurrentJobs.CurrentRow.
I've also tried:
dgvCurrentJobs.SelectedRow
Both of the above work in respect of returning a value from cell 0. But, no matter which row I select, when this line of code is run, it deselects my selection, selects the first row (Index 0) and returns the value in cell 0 of that row, and not the one I had selected. If that makes sense.
Example:
Column 0 | Column 1
--------------------------
R0C0 | R0C1
R1C0 | R1C1
R2C0 | R2C1
If the table above is my DataGridView, and I select the second row which contains "R1C0" in column index 0 and "R1C1" in column index 1; When I press the button that runs the code I mentioned above, the first row containing "R0C0" and "R0C1" becomes highlighted and the value in my msgbox is "R0C0".
Not sure how easy to understand that is, let me know if you cant understand it.
Thanks in advance
mms_master
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window