In this example, a column cell displays not only this field value but also the values of two more fields. Its CellData.Value property provides access to a value of a data field assigned to the column’s GridColumn.FieldName property. The CellData object specifies a binding context for a cell template.
Each cell contains a with three elements bound to the Name, Position and HireDate properties of the Employee class. This column displays names, positions and hire dates of employees.Īssign a template to the TemplateColumn.DisplayTemplate property to define the presentation of column cells. This column displays photos of employees ( images added to a project as embedded resources). Each Employee object contains an employee’s photo (image), name, position, phone, address (strings), hire and birth dates (DateTime values), employee’s access level (enumeration value), and a Boolean value indicating whether an employee is on vacation.Īdd the following columns to the DataGridView.Columns collection: The grid is bound to a collection of Employee objects. This example shows how to create columns in DataGridView to display and edit data of different types. Namespace: ĭ Declaration public class TemplateColumn : A column type that allows you to define a custom template for column cells.