KB Article A1510
Visible to All Users

Can the GridView.ViewRowHandleToDataSourceIndex method be used when the grid's DataSource is a DataTable?

Description:
I am having difficulty obtaining the appropriate index for a row in a DataTable from a focused row in the XtraGrid. ViewRowHandleToDataSourceIndex returns the same value as the FocusedRowHandle passed to it. The following is the code being used:

Visual Basic
Me.NotesView.ViewRowHandleToDataSourceIndex(Me.NotesView.FocusedRowHandle)

Is this the expected behavior or am I using this method incorrectly?

Answer:
Applies to:
XtraGrid v2
When the grid is bound to a DataTable, it actually uses the DataTable.DefaultView object as a data source.* During sorting, rows (DataRowView) are reordered in the underlying DataView. A grid view's row handle corresponds to the row index in the DataView default (indexer) property. Thus, the ViewRowHandleToDataSourceIndex function returns the same value as the parameter value.
However, DataTable rows may have a different order than the rows of the grid and DataView. To obtain a DataRow instance corresponding to a grid view's row handle, you should use the GridView.GetDataRow method.
See Also:
Identifying Rows and Cards
How to obtain a grid row handle by a data row object
* An object, which implements one of the following interfaces can be used by the XtraGrid as a data list:
IList
IBindingList
ITypedList
The DataTable does not implement any of the above interfaces, but implements the IListSource, which is also acceptable by the grid's DataSource property, because the grid can obtain an IList object via the IListSource.GetList method.

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.