Print Page | Close Window

Report Controls Selected Rows in c#

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Suite Pro
Forum Description: Topics Related to Codejock Suite Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=1712
Printed Date: 23 May 2024 at 9:34pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Report Controls Selected Rows in c#
Posted By: amorton
Subject: Report Controls Selected Rows in c#
Date 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




Replies:
Posted By: Boyd
Date Posted: 27 January 2005 at 2:31pm

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)
{
    ArrayList rowsList = new ArrayList();
    for (int j = 0; j < reportControl.Rows.Count; j++)
    {
        if (reportControl.Rows[j].Selected)
        {
              if (includeGroupRow || reportControl.Rows[j].GroupRow == false)
                  rowsList.Add(reportControl.Rows[j]);
        }
    }
    XtremeReportControl.ReportRow[] rows = new XtremeReportControl.ReportRow[rowsList.Count];
    rowsList.CopyTo(rows);
    return rows;
}

I apologize if there are syntax errors... I wrote this from scratch.



Posted By: amorton
Date Posted: 28 January 2005 at 6:39am
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




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net