This example shows how to creating report with Business Objects collection. Business Objects - an object class data with which the data can be presented in different structures: tables, lists, arrays, etc. This example uses two variants of Business Objects - IEnumerable and ITypedList:
private void btPreviewIEnumerable_Click(object sender, System.EventArgs e){
	StiReport report = new StiReport();
	report.RegData("EmployeeIEnumerable", CreateBusinessObjectsIEnumerable.GetEmployees());
	report.Load("..\\BusinessObjects_IEnumerable.mrt");
	report.Show();
}

private void btPreviewITypedList_Click(object sender, System.EventArgs e)
{
	StiReport report = new StiReport();
	report.RegData("EmployeeITypedList", CreateBusinessObjectsITypedList.GetEmployees());
	report.Load("..\\BusinessObjects_ITypedList.mrt");
	report.Show();
}

As IEnumerable object the EmployeeIEnumerable model is used, to populate data the GetEmployees() method of the CreateBusinessObjectsIEnumerable class is used:
public static EmployeeIEnumerableCollection GetEmployees()
{
	EmployeeIEnumerableCollection employees = new EmployeeIEnumerableCollection();
	Company company = new Company("Company1");
	Department storeDepartment = new Department(company, "Store Department");
	Department salesDepartment = new Department(company, "Sales Department");
	
	EmployeeIEnumerable emp = new EmployeeIEnumerable(storeDepartment, "Nicholas", "Nicholas@company1.com");
	emp.Phones.Add(new Phone("(206) 555-9857"));
	emp.Phones.Add(new Phone("(206) 555-6546"));
	emp.Phones.Add(new Phone("(206) 555-7651"));
	employees.Add(emp);
	
	emp = new EmployeeIEnumerable(storeDepartment, "Margaret", "Margaret@company1.com");
	emp.Phones.Add(new Phone("(206) 555-4546"));
	emp.Phones.Add(new Phone("(206) 555-0110"));
	employees.Add(emp);
	
	emp = new EmployeeIEnumerable(storeDepartment, "Janet", "Janet@company1.com");
	emp.Phones.Add(new Phone("(206) 555-5462"));
	emp.Phones.Add(new Phone("(206) 555-8400"));
	emp.Phones.Add(new Phone("(206) 555-9842"));
	employees.Add(emp);
	
	emp = new EmployeeIEnumerable(salesDepartment, "Laura", "Laura@company1.com");
	emp.Phones.Add(new Phone("(206) 555-0022"));
	employees.Add(emp);
	
	emp = new EmployeeIEnumerable(salesDepartment, "Mark", "Mark@company1.com");
	emp.Phones.Add(new Phone("(206) 555-9980"));
	emp.Phones.Add(new Phone("(206) 555-5567"));
	employees.Add(emp);
	
	emp = new EmployeeIEnumerable(salesDepartment, "Michael", "Michael@company1.com");
	emp.Phones.Add(new Phone("(206) 555-5642"));
	employees.Add(emp);
	
	emp = new EmployeeIEnumerable(salesDepartment, "Thomas", "Thomas@company1.com");
	emp.Phones.Add(new Phone("(206) 555-8949"));
	employees.Add(emp);
	
	return employees;
}

As ITypedList object the EmployeeITypedList model is used, to populate data the GetEmployees() method of the CreateBusinessObjectsITypedList class is used:
public static EmployeeITypedListCollection GetEmployees()
{
	EmployeeITypedListCollection employees = new EmployeeITypedListCollection();
	Company company = new Company("Company1");
	Department storeDepartment = new Department(company, "Store Department");
	Department salesDepartment = new Department(company, "Sales Department");
	
	EmployeeITypedList emp = new EmployeeITypedList(storeDepartment, "Nicholas", "Nicholas@company1.com");
	emp.Phones.Add(new Phone("(206) 555-9857"));
	emp.Phones.Add(new Phone("(206) 555-6546"));
	emp.Phones.Add(new Phone("(206) 555-7651"));
	employees.Add(emp);
	
	emp = new EmployeeITypedList(storeDepartment, "Margaret", "Margaret@company1.com");
	emp.Phones.Add(new Phone("(206) 555-4546"));
	emp.Phones.Add(new Phone("(206) 555-0110"));
	employees.Add(emp);
	
	emp = new EmployeeITypedList(storeDepartment, "Janet", "Janet@company1.com");
	emp.Phones.Add(new Phone("(206) 555-5462"));
	emp.Phones.Add(new Phone("(206) 555-8400"));
	emp.Phones.Add(new Phone("(206) 555-9842"));
	employees.Add(emp);
	
	emp = new EmployeeITypedList(salesDepartment, "Laura", "Laura@company1.com");
	emp.Phones.Add(new Phone("(206) 555-0022"));
	employees.Add(emp);
	
	emp = new EmployeeITypedList(salesDepartment, "Mark", "Mark@company1.com");
	emp.Phones.Add(new Phone("(206) 555-9980"));
	emp.Phones.Add(new Phone("(206) 555-5567"));
	employees.Add(emp);
	
	emp = new EmployeeITypedList(salesDepartment, "Michael", "Michael@company1.com");
	emp.Phones.Add(new Phone("(206) 555-5642"));
	employees.Add(emp);
	
	emp = new EmployeeITypedList(salesDepartment, "Thomas", "Thomas@company1.com");
	emp.Phones.Add(new Phone("(206) 555-8949"));
	employees.Add(emp);
	return employees;
}

In the screenshot below you can see the result of the sample code:

Using Business Objects in the Report

By using this website, you agree to the use of cookies for analytics and personalized content. Cookies store useful information on your computer to help us improve efficiency and usability. For more information, please read the privacy policy and cookie policy.