We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to map DataRow index and Grid index

Thread ID:





26829 Apr 1,2005 08:05 AM UTC Apr 1,2005 09:47 AM UTC WinForms 1
Tags: GridControl
Hoang Dinh
Asked On April 1, 2005 08:05 AM UTC

Hi, I don''t know how to map datarow index and grid index in GridDataBoundGrid. Ex: - I have a datatable which have 10 rows. - Using method "grid.DataSource=dt" to bind data. - after that, I used "DeleteRecordsAtRowIndex" to delete 5 rows. And now, in the grid, there are 5 rows - And in datatable still exists 10 rows( 5 rows is marked as Deleted and 5 rows is marked as Unchanged) Please let me know how to get the position in the grid if I know the row index in datatable. Thanks

Administrator [Syncfusion]
Replied On April 1, 2005 09:47 AM UTC

If you use "grid.DataSource=dt", then the grid is really bound to dt.DefaultView. You need to use the DataView, and not the Datatable, to support things like sorting and deleting. If your grid is sorted, the DataTable is no longer mapped 1 to 1 with the rows in the grid. it is the Dataview that is mapped 1-1 with the rows in the grid. Given a position in the DataView (or more generally in the CurrencyManager.List), you can get the rowIndex in the grid using grid.Binder.PositionToRowIndex method. Given a rowIndex in the grid, you can use grid.Binder.RowIndexToPosition to get the position in the DataView or (CurrencyManager.List). For example, to get the DataRow object from your DataTable associated with the grid row at rowIndex, use code like: int position = grid.Binder.RowIndexToPosition(rowIndex); CurrencyManager cm = grid.BindingContext[grid.DataSource, grid.DataMember] as CurrencyManager; DataView dv = cm.List as DataView; DataRowView drv = dv[position]; DataRow dr = drv.Row; Now if you want to find a grid rowIndex from some arbitary position in the DataTable, you muts first find where this arbitary position is in the associated DataView. If things are sorted, you can use DataView.Find or soemthing similar. If they are not, then you may have to loop through the dataview to locate the position. Once you have the position in the DataView, you can use grid.Binder.PositionToRowIndex to get teh grid row.


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon