The RadGridView for WPF uses the ItemsSource property for binding data. ItemsSource is actually of type System.Object which not only allows you to bind to any data source that implements IEnumerable, but also the ADO.NET DataTable and DataSet. In this post, I am going to demonstrate how you can quickly bind data to the RadGridView for WPF. The task will be to build a car repair shop application which will display all the cars currently in the shop. To get started we need to have some data, so we will use a simple class to store Car information.
Now to keep the example simple we can create a routine to build a List of Car objects. I called this routine GetCarsInTheShop and creates two new Car objects and add them to the List<Car> which is returned to the caller.
Now that the preparation steps are out of the way, the next step is to drag and drop a new RadGridView onto the Window. You will notice that the grid displays sample data during design time, but this will not be visible when you run the application.
Finally, it is time to bind the data to the RadGridView in the constructor of the Window. As you will see in the code below, I am simply assigning the resulting List<Car> from the GetCarsInTheShop routine to ItemsSource property.
After I run the application and the data is displayed appropriately in the grid, as expected. Not only that, but the appropriate editor for the cell datatype is displayed when you enter edit mode.
ModelYear (DateTime data type) displays DatePicker editor for cell.
AllWheelDrive (Boolean data type) displayed CheckBox editor for cell.
And there you have it, this shows just how simple it is to bind data to the RadGridView for WPF.
Copyright © 2017, Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks or appropriate markings.