Help. I'm Lost. How to retrieve the selected row information from a DataGridView
-
Hi. I'm having trouble with a DataGridView. The view displays a list of customers from a query that displays their relevant ID's and names which is bound to a DataTable. When the user double clicks on the customer they want, I would like to get the customer ID of their selection. I've tried
customerDataGrid.SelectedRows(0).Cells(0).Value
but I get an error saying thatSelectedRows
is a property but it is being used as a method. How do I achieve this. I know it is probably simple but I cannot find the info that I need on MSDN and I am at a loss. Your help is much appreciated in advance.The FoZ
-
Hi. I'm having trouble with a DataGridView. The view displays a list of customers from a query that displays their relevant ID's and names which is bound to a DataTable. When the user double clicks on the customer they want, I would like to get the customer ID of their selection. I've tried
customerDataGrid.SelectedRows(0).Cells(0).Value
but I get an error saying thatSelectedRows
is a property but it is being used as a method. How do I achieve this. I know it is probably simple but I cannot find the info that I need on MSDN and I am at a loss. Your help is much appreciated in advance.The FoZ
-
TheFoZ wrote:
but I get an error saying that SelectedRows is a property but it is being used as a method.
Yeah, because that's what it is.
customerDataGrid.SelectedRows[0].Cells[0].Value
regards -
Looks like I'm still in my VB ways with curved brackets instead of square ones. Many Thanks
The FoZ
hey there also you should keep in mind that it is posible to have more than one selected row in a dataGridView unless otherwise set up by you in design time. if thats desired youll have to do the following...
foreach(DataGridRow myRow in myDataGrid.Rows) { // do what ever you need to do with the row }
Harvey Saayman - South Africa Junior Developer .Net, C#, SQL
you.suck = (you.passion != Programming)
-
hey there also you should keep in mind that it is posible to have more than one selected row in a dataGridView unless otherwise set up by you in design time. if thats desired youll have to do the following...
foreach(DataGridRow myRow in myDataGrid.Rows) { // do what ever you need to do with the row }
Harvey Saayman - South Africa Junior Developer .Net, C#, SQL
you.suck = (you.passion != Programming)
-
hey there also you should keep in mind that it is posible to have more than one selected row in a dataGridView unless otherwise set up by you in design time. if thats desired youll have to do the following...
foreach(DataGridRow myRow in myDataGrid.Rows) { // do what ever you need to do with the row }
Harvey Saayman - South Africa Junior Developer .Net, C#, SQL
you.suck = (you.passion != Programming)
HarveySaayman wrote:
posible to have more than one selected row in a dataGridView unless otherwise set up by you in design time
Yes. You can use datagridview1.MultiSelect=false for only allowing one. Brought this up to my students the other day in class.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon