How to Get Values from Datagridview row

I have a datagridview on a form which is bound to a dataset. When the user selects a row I want to get teh values from two of the columns in that row.

I am able to use the following code to get a value a place it in the variable varTransID.

varTransID = TransactionsDataGridView.CurrentRow.Cells(0).Value

However, I am afraid that if the user rearranges the columns then the the column reference will pull fromt he wrong column. IS there any way to reference the column title so that I am sure I get teh right value. Perhaps something like this:

varTransID = ClientsDataGridView.CurrentRow.Cells("TransactionID").Value

Unfortunately the program fails and says it cannot find the column called TransactionID in the above line. IS there another way?

Thanks

[885 byte] By [CarlInMilford] at [2007-12-17]
# 1

Check out the .designer.vb file, there should be variables for the columns, like transactionIdDataGridViewTextBoxColumn. They have a Index property you can use:

clientsDataGridView.CurrentRow.Cells(transactionIdDataGridViewTextBoxColumn.Index).Value

DanielRieck at 2007-9-8 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...