Hi VMI,
Your question as I understood is this:
you have a datagrid, bound to a datatable. The columns, or the sorting etc.
might change in the datagrid.
Regardless of the column position, or the current sort, you want to obtain
the datarow which the user has currently selected in the datagrid. Is this
right?
If yes, then 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.
This is a good article which explains the data binding procedure in windows
forms:
http://msdn.microsoft.com/library/en...dingadonet.asp
HTH,
Rakesh Rajan
"VMI" <vo******@yahoo.com> wrote in message
news:OL**************@TK2MSFTNGP09.phx.gbl...
Hi,
I have a Windows datagrid that's attached to a filled datatable. The grid
also has a tablestyle. Since the data from the grid comes from a
datatatable, how can I retrieve the data from a specific table row once a
user clicks on a grid row? I already have the code that lets me know what
grid row the user clicked on, but, for example, if I want to retrieve the
value of the 5th column in the grid, I'm currently using myGrid[rowNum,
4].ToString(). But If I decide to change the position of "Name" to column
8, I'll have to change this code (eg. myGrid[rowNum, 7].ToString() ). Is
there any other alternative?
Thanks.