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 ObjectsDefine 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 DesignWinForms UI Controls WinForms Buttons UI Control WinForms Calendar UI ControlWinForms Carousel UI ControlWinForms Chart UI ControlWinForms Clock UI ControlCommandBar UI ControlWinForms Dock UI ControlDesktop Alert UI ControlDropDown List UI ControlWinForms Editor UI ControlForms and Dialogs UI ControlWinForms GridView UI ControlGridView - Get Started in C#GridView - PropertiesGridView - ColumnGridView - RowGridView - CellsGridView - EditorsGridView - Context MenuConditional Custom Context MenuModify Default Context MenuGridView - Populating with DataData BindingBinding to Array and ArrayListBinding to Generic ListBinding to Binding ListBinding to DataTable / DataSetBinding to DataReaderBinding to Sub ObjectsBinding to XMLUnbound ModeUpdate DatabaseGridView - Hierarchical GridGridView - SelectionGridView - ScrollingGridView - SortingGridView - GroupingGridView - FilteringGridView - Expression EditorInsert/ Update/ Delete RecordsGridView - View DefinitionGridView - Exporting DataStyling and AppearanceGridView - LocalizationSave and Load LayoutGridView - Print SupportWinForms ListView UI ControlWinForms Menu UI ControlWinForms ComboBox UI ControlWinForms PageView UI ControlPanels and Labels UI ControlWinForms Panorama UI ControlWinForms PDFViewer UI ControlWinForms Property Grid UI ControlWinForms Ribbon UI ControlWinForms PivotGrid UI ControlWinForms RichTextBox UI ControlWinForms Rotator UI ControlWinForms Scheduler UI ControlWinForms Shortcuts UI ControlWinForms SpellChecker UI ControlWinForms Track & Status UI ControlWinForms TreeView UI ControlWinForms Wizard UI ControlWinForms Test UI ControlWinForms Theme UI Control |