Hello,
I am attempting to manually create a report in the viewmodel to bind to a WPF reportviewer control.
I cannot use the designer as I have to create the table manually. The report will accept a datasource object (in this instance a List<T> where T is a domain object), create the columns, and then populate the rows. I have done extensive research on the forums and created the column collection and even the entire table. I am unable to get it to show anything once the report is bound to the view.
Any help is appreciated.
-Josh
Here is the xaml for the report viewer:
I am attempting to manually create a report in the viewmodel to bind to a WPF reportviewer control.
I cannot use the designer as I have to create the table manually. The report will accept a datasource object (in this instance a List<T> where T is a domain object), create the columns, and then populate the rows. I have done extensive research on the forums and created the column collection and even the entire table. I am unable to get it to show anything once the report is bound to the view.
Any help is appreciated.
-Josh
Here is the xaml for the report viewer:
<telerikReporting:ReportViewer Grid.Row="1" x:Name="ReportViewer1" Report="{Binding DataContext.AutoReport}" Width="500" Height="600" >
</telerikReporting:ReportViewer>
And here is the ViewModel:
using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Collections.Specialized; using System.Linq; using System.Text; using Telerik.Reporting; using Telerik.Reporting.Drawing; using System; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; using Telerik.Reporting; using Telerik.Reporting.Drawing; using System.Data.SqlClient; using System.Data; using System.Text; using System.Collections; namespace Client.ViewModels { public class TelerikDummyReportViewModel : ReportViewModelBase { public TelerikDummyReportViewModel(ContentViewModelBase parent) : base(parent) { } #region Properties private Report _autoreport; public Report AutoReport { get { return _autoreport; } set { // Check if it's really a change if (value == _autoreport) return; // Change Report _autoreport = value; // Notify attached View(s) RaisePropertyChanged("AutoReport"); } } private List<user> _userDataList; public List<user> UserDataList { get { return _userDataList; } set { _userDataList = value; if (_userDataList.Count() > 0) { AutoReport = new DynamicReport(_userDataList[0]); AutoReport.Report.DataSource = UserDataList; } RaisePropertyChanged("UserDataList"); RaisePropertyChanged("AutoReport"); } } #endregion internal override void ControlLoaded() { DependencyCheck(); } internal override void DependencyCheck() { GetUsers(); } public void GetUsers() { ShowIsBusyMessage("Loading ..."); AuthenticationClient.GetLPUsersCompleted += new EventHandler<GetLPUsersCompletedEventArgs>(AuthenticationClient_GetLPUsersCompleted); AuthenticationClient.GetLPUsersAsync(); } void AuthenticationClient_GetLPUsersCompleted(object sender, GetLPUsersCompletedEventArgs e) { AuthenticationClient.GetLPUsersCompleted -= AuthenticationClient_GetLPUsersCompleted; if (e.Error != null) { this.HandlePrompt("Error retrieving audit activity filter.", DisplayName, e.Error); HideIsBusyMessage(); } else if (e.Result != null) { UserDataList = e.Result.ToList(); } HideIsBusyMessage(); } internal class DynamicReport : Telerik.Reporting.Report { private Table table1; public DynamicReport(object sourceObject) { table1 = createTable(sourceObject); } private Table createTable(object sourceObject) { var targetTable = new Table(); targetTable.ColumnGroups.Clear(); targetTable.Body.Columns.Clear(); targetTable.Body.Rows.Clear(); var sourcePropertyList = sourceObject.GetType().GetProperties(); Telerik.Reporting.TextBox textboxGroup; Telerik.Reporting.TextBox textBoxTable; Telerik.Reporting.TableGroup tableGroupColumn; int i = 0; foreach (var o in sourcePropertyList) { tableGroupColumn = new TableGroup(); targetTable.Body.Columns.Add(new TableBodyColumn(Unit.Inch(1))); textboxGroup = new Telerik.Reporting.TextBox(); textboxGroup.Value = o.Name; textboxGroup.Size = new SizeU(Unit.Inch(1.1), Unit.Inch(0.3)); tableGroupColumn.ReportItem = textboxGroup; targetTable.ColumnGroups.Add(tableGroupColumn); textBoxTable = new Telerik.Reporting.TextBox(); targetTable.Body.SetCellContent(0, i++, textBoxTable); textBoxTable.Value = "=Fields." + o.Name; } TableGroup tableGroupRow = new TableGroup(); targetTable.RowGroups.Add(tableGroupRow); tableGroupRow.Grouping.Add(new Telerik.Reporting.Data.Grouping()); targetTable.DataSource = sourceObject; return targetTable; } } } }