Articles in this section
Category / Section

How do I locate the current row in my DataTable after the GridDataBoundGrid has been sorted or filtered?

1 min read

 

You can get the currently selected row in your DataTable through the CurrencyManager even if the table is filtered and/or sorted. If "Col0" is the name of a column in the datatable, you can get at the value of this column in the current row using the below code snippet.

C#

CurrencyManager cm = (CurrencyManager) this.BindingContext[this.gridDataBoundGrid1.DataSource,

this.gridDataBoundGrid1.DataMember];

DataRow dr = ((DataRowView) cm.Current).Row;

this.label1.Text = dr["Col0"].ToString();

VB

Dim cm As CurrencyManager = Me.BindingContext(Me.GridDataBoundGrid1.DataSource,

Me.GridDataBoundGrid1.DataMember)

Dim dr As DataRow = CType(cm.Current, DataRowView).Row

Me.Label1.Text = dr("Col0").ToString()

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied