What is the purpose of External IEnumerables used in DataGrid?
What is the purpose of External IEnumerables used in DataGrid?
- External IEnumerables are used to collect the collection of Items that are supplied with the DataGrid.
- The data that is being displayed is usually having external sources like database connection so DataGrid uses an external collection object.
- Before collection any data it is important to set the ItemsSource property and an object type is created to hold the data.
The example of holding the object type is shown below:
public class Person
{
public string name { set; get; }
public int age { set; get; }
public bool member { set; get; }
}
Collection of these objects needs to be created for the listing of them:
List<Person> myList = new List<Person>();
myList.Add(new Person() {name="hello",age=30,member=true});
myList.Add(new Person() {name="yello",age=25,member=false});
myList.Add(new Person() {name="mello",age=15,member=true});
To display the collection the DataGrid object is used like:
dataGrid.ItemsSource=makeList;