can some one tell me why this example of how to use the telerik gridview does not work there seems to be an issue at the line highlighted below:
I have added my own class as well as re-arranged the sample class and called the Method from the sample class to populate my radgridview but it does not work please see my comments in the
private ObservableCollection<Customer> GetObservableObjectData() Method i am calling from below this sample
that shows what does not work?
public class Customer
{
public Customer(int ID, string Name, string Address, DateTime DateOfRegistration,
bool Discontinued)
{
this.ID = ID;
this.Name = Name;
this.Address = Address;
this.DateOfRegistration = DateOfRegistration;
this.Discontinued = Discontinued;
}
public int ID { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public DateTime DateOfRegistration { get; set; }
public bool Discontinued { get; set; }
}
private ObservableCollection<Customer> GetObservableObjectData()
{
***** return new ObservableCollection<Customer>(GetData()); //this line DOES NOT WORK!!!!!!!!!!
}
public IEnumerable<Customer> GetData()
{
return from i in Enumerable.Range(0, names.Length)
select new Customer(i, names[i], addresses[i],
dates[i], bools[i]);
}
string[] names = new string[] { "Anthony Smith", "Maria Angeles",
"Stephan Pitt", "Mary Johnes", "Silvia Johnson",
"Victoria Ashworth", "Hanna Moos", "Thomas Hardy", "Patricio Simpson", "Francisco Chang" };
string[] addresses = new string[] { "Obere Str. 57", "Avda. de la Constitució2222", "Mataderos 2312", "Fauntleroy Circus",
"Cerrito 333", "Sierras de Granada 9993", "67, rue des Cinquante Otages", "Rua Oró92", "Rua Oró95", "Walserweg 21" };
DateTime[] dates = new DateTime[] { new DateTime(2007, 5, 10), new DateTime(2008, 9, 13),
new DateTime(2008, 2, 22), new DateTime(2009, 1, 2), new DateTime(2007, 4, 13),
new DateTime(2008, 5, 12), new DateTime(2008, 1, 19), new DateTime(2008, 8, 26),
new DateTime(2008, 7, 31), new DateTime(2007, 7, 16) };bool[] bools = new bool[] { true, false, true, false, true, false, true, false, true, false };
Below is my own code in using this to populate a grid view which saya there is no constructor that take s GetData();
public
partial class MainPage : UserControl
{
IEnumerable<Customer> CustEnum;
public MainPage()
{
InitializeComponent();
Customer cust = new Customer(1, "Kingsley", "123 the Moon", DateTime.Now, false);
CustEnum = cust.GetData();
//call to....
this.rdgv1.ItemsSource = GetObservableObjectData();
}
//this method...
private ObservableCollection<Customer> GetObservableObjectData()
{
//This line compiles but no data is returned as GetData() is not called!
//return new ObservableCollection<Customer>();
// This line does not work as there is no Customer constructor that accepts IEnumerable<Customer> method such as GetData()
//obviously to return the data! This is obviously a mistake by Telerik can someone please adress or advise ??
return new ObservableCollection<Customer>(GetData());
}
}
public class Customer
{
//Vars
string[] names = new string[] { "Anthony Smith", "Maria Angeles",
"Stephan Pitt", "Mary Johnes", "Silvia Johnson",
"Victoria Ashworth", "Hanna Moos", "Thomas Hardy", "Patricio Simpson", "Francisco Chang" };
string[] addresses = new string[] { "Obere Str. 57", "Avda. de la Constituci2222", "Mataderos 2312", "Fauntleroy Circus",
"Cerrito 333", "Sierras de Granada 9993", "67, rue des Cinquante Otages", "Rua Or92", "Rua Or95", "Walserweg 21" };
DateTime[] dates = new DateTime[] { new DateTime(2007, 5, 10), new DateTime(2008, 9, 13),
new DateTime(2008, 2, 22), new DateTime(2009, 1, 2), new DateTime(2007, 4, 13),
new DateTime(2008, 5, 12), new DateTime(2008, 1, 19), new DateTime(2008, 8, 26),
new DateTime(2008, 7, 31), new DateTime(2007, 7, 16) };
bool[] bools = new bool[] { true, false, true, false, true, false, true, false, true, false };
//Properties
public int ID { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public DateTime DateOfRegistration { get; set; }
public bool Discontinued { get; set; }
//constructor
public Customer(int ID, string Name, string Address, DateTime DateOfRegistration, bool Discontinued)
{
this.ID = ID;
this.Name = Name;
this.Address = Address;
this.DateOfRegistration = DateOfRegistration;
this.Discontinued = Discontinued;
}
public IEnumerable<Customer> GetData()
{
return from i in Enumerable.Range(0, names.Length)
select new Customer(i, names[i], addresses[i],
dates[i], bools[i]);
}
}
can someone please take a look