DataGridViewButtonColumn Class
Assembly: System.Windows.Forms (in system.windows.forms.dll)
The DataGridViewButtonColumn class is a specialized type of the DataGridViewColumn class used to logically host cells that respond to simple user input. A DataGridViewButtonColumn has an associated DataGridViewButtonCell in every DataGridViewRow that intersects it. Each cell supplies a user interface (UI) that is similar to a Button control.
To display the same button text for every cell, set the UseColumnTextForButtonValue property to true and set the Text property to the desired button text.
The default sort mode for this column type is NotSortable.
To respond to user button clicks, handle the DataGridView.CellContentClick event.
Note |
|---|
| When visual styles are enabled, the buttons in a button column are painted using a ButtonRenderer, and cell styles specified through properties such as DefaultCellStyle have no effect. |
The following code example demonstrates how to use a DataGridViewButtonColumn to view the sales an employee has made.
Private Sub AddButtonColumn() Dim buttons As New DataGridViewButtonColumn() With buttons .HeaderText = "Sales" .Text = "Sales" .UseColumnTextForButtonValue = True .AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells .FlatStyle = FlatStyle.Standard .CellTemplate.Style.BackColor = Color.Honeydew .DisplayIndex = 0 End With DataGridView1.Columns.Add(buttons) End Sub
System.Windows.Forms.DataGridViewElement
System.Windows.Forms.DataGridViewBand
System.Windows.Forms.DataGridViewColumn
System.Windows.Forms.DataGridViewButtonColumn
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
Reference
DataGridViewButtonColumn MembersSystem.Windows.Forms Namespace
DataGridView Class
DataGridViewColumn
DataGridViewRow
DataGridViewButtonCell Class
Button Class
DataGridViewColumn.SortMode
DataGridView.CellClick Event
Note