Bind GridView C#.NET to Sub Objects
The Kettic DataGridView Component allows users of the control binding the control to subjects out of the box. This is achieved by use simple dot syntax which is specified via the FieldName property of bound grid columns declaratively. We are going through the example below to demonstrate how to bind the GridView control to sub objects. There is a Person C# class defined by three properties, of which the first property is the Name, which is string, the second property is the City, which is also string, and the third is the Car property, which is the reference type Car, sub object.
How to Bind GridView to Sub Objects
Define Class and Sub Object of Class
Before we are going to bind the GridView to the sub objects, we need to define the person C# class first. The C# code below shows the details of defining the Person class and the sub class, Car.
Bind to Sub Object of Class
After defining the Person class and the sub object of the class, Car, we can populate a BindingList of the Person C# class with some objects and bind the GridView component to these objects. Having bound the GridView to the Person C# class, three new columns for all properties of the Person C# class object will be created automatically. The C# code below shows how to bind GridView control to sub objects of the class.
After finishing the above step, we can customize the sub property binding of the Car column. We can achieve this by declaring in the FieldName property of the grid column, and the Car object property name binding to the column. The following are the simple C# code snippet to bind GridView to sub objects.
UI Controlsfor Windows Forms.NET WinForms UI Overview.NET WinForms UI Features.NET WinForms UI GuideC# WinForms UI DesignVB.NET WinForms UI Design
WinForms UI Controls