Skip to content

Latest commit

 

History

History
39 lines (28 loc) · 2.51 KB

unbound-column-to-a-data-bound-datagridview.md

File metadata and controls

39 lines (28 loc) · 2.51 KB
title ms.date dev_langs helpviewer_keywords ms.assetid description
Add an Unbound Column to a Data-Bound DataGridView Control
03/30/2017
csharp
vb
columns [Windows Forms], unbound data
data grids [Windows Forms], adding unbound columns
DataGridView control [Windows Forms], unbound data
f7bdc4d8-ba8e-421b-ad62-82d936f01372
Learn how to add an unbound column to a data-bound Windows Forms DataGridView control to display a column of data that does not come from the data source.

How to: Add an Unbound Column to a Data-Bound Windows Forms DataGridView Control

The data you display in the xref:System.Windows.Forms.DataGridView control will normally come from a data source of some kind, but you might want to display a column of data that does not come from the data source. This kind of column is called an unbound column. Unbound columns can take many forms. Frequently, they are used to provide access to the details of a data row.

The following code example demonstrates how to create an unbound column of Details buttons to display a child table related to a particular row in a parent table when you implement a master/detail scenario. To respond to button clicks, implement a xref:System.Windows.Forms.DataGridView.CellClick?displayProperty=nameWithType event handler that displays a form containing the child table.

There is support for this task in Visual Studio. Also see How to: Add and Remove Columns in the Windows Forms DataGridView Control Using the Designer.

Example

[!code-csharpSystem.Windows.Forms.DataGridViewMisc#010] [!code-vbSystem.Windows.Forms.DataGridViewMisc#010]

Compiling the Code

This example requires:

  • A xref:System.Windows.Forms.DataGridView control named dataGridView1.

  • References to the xref:System?displayProperty=nameWithType and xref:System.Windows.Forms?displayProperty=nameWithType assemblies.

See also