I am using a collection of business entity objects as data source for my GDBG. Everything is working my.
In QueryCellInfo event I need to get the associated business object for e.RowIndex. How do I get it?
If I use the following code I always get the object for the current selected row.
CurrencyManager cm = this.gdbgMyGrid.BindingContext[gdbgMyGrid.DataSource, gdbgMyGrid.DataMember] as CurrencyManager;
MyObject myObject = (MyObject)cm.Current;
Please do help me.
VS
AD
Administrator
Syncfusion Team
December 7, 2005 07:01 PM UTC
Try:
CurrencyManager cm = this.gdbgMyGrid.BindingContext[gdbgMyGrid.DataSource, gdbgMyGrid.DataMember] as CurrencyManager;
MyObject myObject = (MyObject)cm.List[e.RowIndex - 1];
ST
Sebastien Thuilliez
December 8, 2005 02:08 PM UTC
Clay,
is there any way to retrieve the object like you did above, for the displayed rows ... or a way to link displayed elements to CurrencyManager list.
Thanks in advance.
Seb
AD
Administrator
Syncfusion Team
December 8, 2005 02:30 PM UTC
You can get the grid row indexes of th etop and bottom visible rows using:
int topRowIndex = grid.TopRowIndex;
int botRowIndex = grid.ViewLayout.LastVisibleRow;
To map these to positions in the currencymanager list, you can use grid.Binder.RowIndexToPosition.
int topPosition = grid.Binder.RowIndexToPosition(topRowIndex);
int botPosition = grid.Binder.RowIndexToPosition(botRowIndex );
ST
Sebastien Thuilliez
December 8, 2005 02:48 PM UTC
Thanks for your answer Clay.
Anyway I didn''t find the TopRowIndex neither the ViewLayout.LastVisibleRow ... are these method coming from GridControl or GridGroupingControl.
My mistake, I didn''t gave you any information, more details :
I''m using GridGroupingControl with FilterBar .. and due to the filter items I need to only apply computation/process on the displayed rows but the CurrencyManager give me all existing records.
Thanks again for your time !
AD
Administrator
Syncfusion Team
December 8, 2005 02:56 PM UTC
If you are using a GridGroupingControl, it is simpler to get the filtered list from the Table.Filteredrecords collection. This collection will hold exactly the records being displayed in the Table.
DataRowView drv = this.gridGroupingControl1.Table.FilteredRecords[position].GetData() as DataRowView;
ST
Sebastien Thuilliez
December 8, 2005 03:17 PM UTC
Like you said, I used
MyCustomObject myItem = null;
myItem = groupingControl.Table.FilteredRecords[index].GetData() as MyCustomObject;
and it works perfectly.
It will simplify a lot my source code for this part.
Thanks again for your quick and very effective support.