Добавить элемент управления в конструктор активного отчета
Я знаю, что есть разные способы добавить элементы управления в Active Report. Я нашел их на разных веб-страницах, таких как:
this.Sections["groupHeader1"].Controls.Add(txt);
Но это не мое дело, я должен загрузить дизайнер, т.е. GrapeCity.ActiveReport.Design.Designer
с некоторыми элементами управления. Я хочу добавить эти элементы управления из моего кода. Пожалуйста, помогите мне.
3 ответа
Если вы просматриваете конструктор конечных пользователей и хотите добавить элементы управления в разделы отчетов на основе секций, то вам нужно будет создать отчет конструктора конечных пользователей с использованием класса SectionReport и получить к нему доступ соответственно. Например, проверьте следующий код, который добавляет текстовое поле в раздел "Сведения" отчета при нажатии кнопки:
private void button1_Click(object sender, EventArgs e)
{
GrapeCity.ActiveReports.SectionReportModel.TextBox txtBox = new GrapeCity.ActiveReports.SectionReportModel.TextBox();
txtBox.Text = "Hello World!";
txtBox.Location = new Point(1, 1);
txtBox.Size = new SizeF(2, 0.5f);
((GrapeCity.ActiveReports.SectionReport)reportdesigner.Report).Sections["Detail"].Controls.Add(txtBox);
}
Здесь reportDesigner - это имя элемента управления конструктора. Надеюсь это поможет.
Ниже приведен код, который вы можете поместить в событие загрузки формы.
GrapeCity.ActiveReports.SectionReport sectionReport = new GrapeCity.ActiveReports.SectionReport();
sectionReport.Sections.Add(GrapeCity.ActiveReports.Document.Section.SectionType.Detail, "Body");
GrapeCity.ActiveReports.SectionReportModel.TextBox MyTextBox = new GrapeCity.ActiveReports.SectionReportModel.TextBox();
MyTextBox.Text = "My Runtime Text";
MyTextBox.ShrinkToFit = true;
MyTextBox.DataField = "ID";
sectionReport.Sections[0].Controls.Add(MyTextBox);
Я сделал это, имея новый SectionReport
и принимая Designer.Report
в этом. Теперь добавляем элемент управления в SectionReport
означает добавление элемента управления в Designer.Report
, Это то, что я думаю о следующем решении, так как оно сработало для меня.
Dim sr As New GrapeCity.ActiveReports.SectionReport()
sr = Me.reportdesigner.Report
''Adding Detail section
sr.Sections.Insert(1, New GrapeCity.ActiveReports.SectionReportModel.Detail())
sr.Sections(1).BackColor = Color.PeachPuff
sr.Sections(1).Height = 1.5F
Dim lbl2 As New GrapeCity.ActiveReports.SectionReportModel.Label()
lbl2.Location = New PointF(0, 0.05F)
lbl2.Text = "Category ID"
lbl2.Alignment = GrapeCity.ActiveReports.Document.Section.TextAlignment.Center
lbl2.Font = New System.Drawing.Font("Arial", 10, FontStyle.Bold)
sr.Sections(1).Controls.Add(lbl2)
Сообщите мне, если есть какая-либо проблема в этом ответе.