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.
Syncfusion Feedback

Sorted GridDataBoundGrid and PushButtonClicked

Thread ID:

Created:

Updated:

Platform:

Replies:

2032 Dec 10,2002 10:46 PM UTC Dec 11,2002 02:13 PM UTC Windows Forms 2
loading
Tags: GridControl
Sean Greer
Asked On December 10, 2002 10:46 PM UTC

How do I get the proper index into the underlying datasource when handling GridDataBoundGrid.PushButtonClicked? This is the code that I'm using currently and it works fine except when the grid is sorted: int nIndex = m_Grid.Binder.RowIndexToListManagerPosition(e.RowIndex); CurrencyManager cm = this.BindingContext[this.m_dsAccountDataSet, "Accounts"] as CurrencyManager; DataRowView drv = cm.List[nListIndex] as DataRowView; When the grid is sorted it returns the row index of the grid, not the row index *in the DataTable* of the DataRow that is being displayed. Thanks, Sean

Administrator [Syncfusion]
Replied On December 11, 2002 07:57 AM UTC

> > How do I get the proper index into the underlying datasource when handling GridDataBoundGrid.PushButtonClicked? This is the code that I'm using currently and it works fine except when the grid is sorted: > > int nIndex = m_Grid.Binder.RowIndexToListManagerPosition(e.RowIndex); > CurrencyManager cm = this.BindingContext[this.m_dsAccountDataSet, "Accounts"] as CurrencyManager; > DataRowView drv = cm.List[nListIndex] as DataRowView; > > When the grid is sorted it returns the row index of the grid, not the row index *in the DataTable* of the DataRow that is being displayed. > > Thanks, > > Sean Sean, I assume you meant nListIndex on the last line to be nIndex, right? Now the drv is the clicked row. You can see this by looking at values in the drv.Row member. They will be the values from the clicked grid row. If you want to make a change to this row, you can access it to make teh change through the drv.Row member. There would not be any need for the original table index. But if you really do need the original table index, there is work to be done. One way would be to grab the primary key from drv.Row and search for it in the table. This would take some effort. A simpler way might be to add a hidden column to the table that originally has the row index in it. Then as the rows are sorted this row index will move with the sort. Then you could use drv.Row to access this column to return its position in the table. Attached is a sample showing what I mean.

Sean Greer
Replied On December 11, 2002 02:13 PM UTC

Clay, You're correct, I had trimmed the variable name to make it more compact in the message. My mistake was that the CurrencyManager's List member does not reflect the sorted state of the DataView. If I instead access the DataView that the grid is based upon, then the RowIndex represents the correct row in the sorted data. Working with a new tool set is so much fun! With the old WinForms grid I would have used the DataView, but I grabbed some sample code for the Essential Grid and figured things were done differently. Thanks, Sean

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.

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

;