The Syncfusion native Blazor components library offers 70+ UI and Data Viz web controls that are responsive and lightweight for building modern web apps.
.NET PDF framework is a high-performance and comprehensive library used to create, read, merge, split, secure, edit, view, and review PDF files in C#/VB.NET.
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
ADAdministrator Syncfusion Team 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.
SGSean GreerDecember 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