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.
Unfortunately, activation email could not send to your email. Please try again.

How to map DataRow index and Grid index

Thread ID:

Created:

Updated:

Platform:

Replies:

26829 Apr 1,2005 03:05 AM Apr 1,2005 04:47 AM Windows Forms 1
loading
Tags: GridControl
Hoang Dinh
Asked On April 1, 2005 03:05 AM

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 04:47 AM

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.

CONFIRMATION

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.

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.

;