This is a migrated thread and some comments may be shown as answers.

[Solved] RadGridView Getting Started Sample not working!

1 Answer 121 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Kingsley Magnus-Eweka
Top achievements
Rank 1
Kingsley Magnus-Eweka asked on 20 Aug 2009, 01:52 PM
Hi all,
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

1 Answer, 1 is accepted

Sort by
0
Missing User
answered on 20 Aug 2009, 02:17 PM
Hi Kingsley Magnus-Eweka,

Thank you for your feedback. You are right that the C# code presented in the help topic is not quite correct. The mistake is corrected and the fix will be added as soon as possible. Your Telerik points are updated.
This should be the correct C# code:

public partial class MainPage : UserControl    
    {    
        public MainPage()    
        {    
            InitializeComponent();    
            this.RadGridView1.ItemsSource = GetObservableObjectData();     
        }    
   
        private ObservableCollection<Customer> GetObservableObjectData()    
        {    
            ObservableCollection<Customer> Customers = new ObservableCollection<Customer>();    
            foreach (Customer ThisCustomer in GetData())    
            {    
                Customers.Add(ThisCustomer);    
            }    
            //Customers = (ObservableCollection<Customer>) GetData();    
            return Customers;    
        }    
   
        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[] { truefalsetruefalsetruefalsetruefalsetruefalse };    
   
    }    
   
    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 { getset; }    
        public string Name { getset; }    
        public string Address { getset; }    
        public DateTime DateOfRegistration { getset; }    
        public bool Discontinued { getset; }    
    }   

Hope this helps.

Best wishes,
Anastasia
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
Kingsley Magnus-Eweka
Top achievements
Rank 1
Answers by
Missing User
Share this question
or