This isn't really necessary. What you usually do is this: find the row which
is the currently selected in a control. You could use the Binding Manager to
find out the current
object/row that the bound datagrid is now referring to. For example, to get
the current row, use:
((CurrencyManager)BindingContext[datatablename]).Current.
Cast this into a datarow (or your typed one), and then use it.
Once you have the row, you could get the primary key or whatever field you
require.
Your method will work, but it not the .NET way of doing things