This example illustrates how to replace an existing component (data source) with a new one and assign it to a report.
Files to Review
Does this example address your development requirements/objectives?
(you will be redirected to DevExpress.com to submit your response)
Example Code
C#using System.ComponentModel;
using System.Windows;
using DevExpress.DataAccess.ObjectBinding;
using DevExpress.Xpf.Reports.UserDesigner;
using DevExpress.XtraReports.UI;
namespace WpfApplication1 {
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
designer.OpenDocument(new XtraReport1());
}
void ReplaceDataSource_ItemClick(object sender, DevExpress.Xpf.Bars.ItemClickEventArgs e)
{
var newDataSource = new ObjectDataSource { DataSource = typeof(MyDataClass) };
XtraReport report = designer.ActiveDocument.Diagram.RootItem.XRObject;
var oldDataSource = report.DataSource as IComponent;
designer.ActiveDocument.MakeChanges(changes => {
if(oldDataSource != null) {
changes.RemoveItem(oldDataSource);
}
changes.AddItem(newDataSource);
changes.SetProperty(report, x => x.DataSource, newDataSource);
});
MessageBox.Show("The data source was replaced from SQL to Object.\n\n Click Undo to cancel.");
}
}
}