Report Controls Selected Rows in c# |
Post Reply |
Author | |
amorton
Newbie Joined: 29 December 2004 Location: United Kingdom Status: Offline Points: 10 |
Post Options
Thanks(0)
Posted: 27 January 2005 at 9:48am |
Hello there, i had been using the report control in VB and decided in see how well it would go in dot net.
In VB6 i had issues with accessing the selected rows for the report, i needed to do a for each to get the selected row even when there was only one row selected as there is no Item property on the selectedRows collection. When i use the control in dot net things get worse. The tlb importer cannot detect whatever process is used to provide enumeration in vb and so does not provide a way to get a IEnumerator for the collection. So there is no way to peform a foreach. As there is no item accessor for the collection i cannot see how to access any of the rows int he selected rows collection. If anyone knows how to do this could they let me know please. thanks aaron |
|
Boyd
Senior Member Joined: 08 December 2003 Location: United States Status: Offline Points: 285 |
Post Options
Thanks(0)
|
Try the following. It will return an array of all the selected rows (with the option to exclude any grouped rows). This function assumes that your report control is accessible to the method through the 'reportControl' variable. public XtremeReportControl.ReportRow[] GetSelectedRows(bool includeGroupRows) I apologize if there are syntax errors... I wrote this from scratch. Edited by Boyd |
|
amorton
Newbie Joined: 29 December 2004 Location: United Kingdom Status: Offline Points: 10 |
Post Options
Thanks(0)
|
Thanks for the reply, i realised that was a option but i wanted to try
and avoid it if possible. After all there is a COM enumerator
available, so i worked out how to get to it. It goes something like
this...
The definition of the IReportSelectedRows interface (from ole view) is a dispactch interface and there is no definition of the _NewEnum property. However this prop is allways implemented with a dispatch ID of -4 so vb will just call Invoke on the IDispatch interface with -4 to get the enumerator for a for each loop. The com enumerator returned implements IEnumVARIANT com interface, i did not check for any other interfaces. Which is not that different to the IEnumerable interface in dot net. When an active x dll is imported dot net uses AxImp.exe to make the active X host sub class, it is an object of this class that represents the control on the page. This utility can export the source it creates for the ax host sub class. So i used AxHost to make a c# class that hosts the report control. I then added a function to the report control in dot net called SelectedRowsEnumerator that returns a object that can be used for for-each in c#. This function : 1 - casts the base ocx controls selectedRows property/object to a dot net definition of the COM IDispatch interface. 2 - Calls invoke on the dispatch interface to invoke the get property with disp ID -4, this is the _NewEnum property. It is possible to call things by name a little easier in dot net i think, but i was not sure how and not sure if the ocx class would implement a call by name considering it was not declared in the interface. 3 - casts the result of the invoke to a dot net definition of the IEnumVARIANT interface. 4 - returns a class that implements both IEnumerable and IEnumerator and wraps access to the com based enumerator returned in step 4 above. The IEnumerable implementation just returns itself so the object can be used in a for each statement. So now i can write code like this in c# foreach (XtremeReportControl.ReportRow row in report.SelectedRowsEnumerator()) { } I also added a property to get the first item in the collection to make things easier when there is one item selected. hope that helps. aaron |
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |