I am trying to bind the DataForm ItemsSource to a DataTable. Initially the DataForm is populated, but if I try to navigate through the records, I get an error.
I have spent past hour searching for a solution, and I could not find any mention of this issue. DataForm works fine if binded to an ObservableCollection of business objects. But in this case I need it binded to a DataTable, and I cant seem to find a way to get it working.
IDE: VS2010
.Net Version: 4.0
Telerik Version: 2011.3.1220.40
I have created a sample project that recreates the same issue. The error that I receive when navigating through the records is:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;
namespace Testing.DataForm
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
GenerateSomeData();
}
private void GenerateSomeData()
{
#region Data Generator
DataTable baseTable = new DataTable();
baseTable.Columns.Add("DateTime", typeof(DateTime));
baseTable.Columns.Add("Value", typeof(decimal));
DateTime date = new DateTime(DateTime.Now.Year, 11, 1);
TimeSpan span = date.AddMonths(1).AddDays(-1) - date;
int numDays = span.Days;
int randHigh = 65;
int randLow = 0;
#region RANDOM DATA GENERATOR
Random rand = new Random();
int calculatedNumHours = 24 * numDays;
for (int hour = 1; hour <= calculatedNumHours; hour++)
{
baseTable.Rows.Add(new object[]
{
date.AddHours(hour).AddSeconds(-1),
rand.NextDouble() * ((randHigh - randLow) + randLow)
});
}
#endregion
dataForm.ItemsSource = baseTable.DefaultView;
#endregion
}
}
}