프린터로 내용 출력하는 방법에 대해 다룹니다.
예시는 visualstudio 2015 Community edition 을 사용 합니다.
설치 시 SQL Server Data Tools 항목이 체크되어 있어야 합니다. 컨트롤이 보이지 않으면 프로그램 추가/제거 에서 변경을 누른다음 체크 하여 추가하도록 합니다.
도구상자 에서 ReportViewer 컨트롤을 폼에 추가 합니다.

새 항목 추가 - 데이터 집합 추가

데이터 집합 -> 추가 - DataTable

테이블 생성
테이블 명을 지정하고, Ctrl+L 을 눌러 컬럼을 하나씩 추가합니다. (Ctrl+L 누를때마다 컬럼이 하나씩 늘어납니다)

레포트 생성
새 항목 추가 - 보고서

보고서에 테이블 추가
이름은 적당히 알아서 지정하고, 데이터 원본과 데이터 집합은 위에서 생성한 데이터 집합의 내용을 선택합니다.

데이터 집합으로 부터 하나씩 끌어다 각 컬럼에 올립니다.
제목 출력을 위한 매개변수도 하나 추가, 배치 합니다.

작업한 보고서를 컨트롤에 연결
Report Viewer 선택 - 우상단 작은 삼각형 클릭 - 팝업에서 보고서 선택

소스코드
데이터 테이블 넘길때 이름을 위에서 지정한 데이터 집합에 설정한 이름으로 넘깁니다.
제목 파라메터 역시 레포트에서 생성한 파라메터 명칭으로 넘깁니다.
DataTable dt = new DataTable();
dt.Columns.Add("Name");
dt.Columns.Add("Tel");
dt.Columns.Add("Addr");
dt.Rows.Add(new object[] { "AAA1", "BBB1", "CCC1" });
dt.Rows.Add(new object[] { "AAA2", "BBB2", "CCC2" });
dt.Rows.Add(new object[] { "AAA3", "BBB3", "CCC3" });
for (int i = 10; i < 100; i++)
{
dt.Rows.Add(new object[] {
string.Format("AAA{0}", i.ToString())
, string.Format("BBB{0}", i.ToString())
, string.Format("CCC{0}", i.ToString()) });
}
ReportParameter[] rp = new ReportParameter[1];
rp[0] = new ReportParameter("title", "샘플 보고서 제목");
reportViewer1.PageCountMode = PageCountMode.Actual;
ReportDataSource rDS = new ReportDataSource("reportdata", dt);
this.reportViewer1.LocalReport.DataSources.Clear();
this.reportViewer1.LocalReport.DataSources.Add(rDS);
this.reportViewer1.LocalReport.SetParameters(rp);
this.reportViewer1.LocalReport.Refresh();
this.reportViewer1.RefreshReport();
빌드 및 실행
테이블이 2페이로 넘어가는 경우, 제목이 보여지지 않습니다.
페이지 마다 테이블 제목을 출력하도록 수정 하도록 하겠습니다.
레포트를 열고 테이블을 선택 합니다.
하단의 고급모드를 선택합니다.

행 그룹 항목의 정적을 클릭 -> 우측 속성에서 RepeatOnNewPage 값을 True 로 설정 합니다.

다시 빌드, 실행 하고 페이지를 넘겨보면 제목이 출력됨을 확인 할 수 있습니다.
본 레포트를 적용하여 개발한 프로그램 소스코드 입니다.
https://github.com/haebi/APTManager