# Cell Button

## Content

True DBGrid for WinForms supports a variety of in-cell button options for the current cell or for all cells within specified columns. Use in-cell buttons to indicate that a list of choices is available, to perform a command associated with the contents of the cell, or to display an arbitrary control or form for editing.

## Enabling the In-Cell Button

To enable the in-cell button for a [C1DisplayColumn](/componentone/docs/win/online-truedbgrid/) object, set its [Button](/componentone/docs/win/online-truedbgrid/) property to **True** in code:

```csharp
this.c1TrueDBGrid1.Splits[0].DisplayColumns[0].Button = true;
```

The [Button](/componentone/docs/win/online-truedbgrid/) property is also enabled when the column's [DropDown](/componentone/docs/win/online-truedbgrid/) property is set to the name of a [C1TrueDBDropDown](/componentone/docs/win/online-truedbgrid/) control, or when the [Presentation](/componentone/docs/win/online-truedbgrid/) property of the associated [ValueItemCollection](/componentone/docs/win/online-truedbgrid/) object is set to one of the combo box options.

By default, the in-cell button displays only for the current cell, as shown in the following image:

![](https://cdn.mescius.io/document-site-files/images/a1b176e5-6638-4b1f-a786-e41a817558bb/images/in-cell-button.png)

However, by setting the column's [ButtonAlways](/componentone/docs/win/online-truedbgrid/) property to **True**, you can force the in-cell button to be displayed in every row:

![](https://cdn.mescius.io/document-site-files/images/a1b176e5-6638-4b1f-a786-e41a817558bb/images/always-button.png)

## Rendering Cells as Command Buttons

To render the current cell as a non-editable command button within a [C1DisplayColumn](/componentone/docs/win/online-truedbgrid/) object, set its [ButtonText](/componentone/docs/win/online-truedbgrid/) property to **True** in code:

```csharp
this.c1TrueDBGrid1.Splits[0].DisplayColumns[0].ButtonText = true;
```

When a cell within the column receives focus, it is rendered as a standard Windows command button using the cell text as the caption. The cell text is not centered automatically, but respects the column's horizontal and vertical alignment settings:
If both the [Button](/componentone/docs/win/online-truedbgrid/) and [ButtonText](/componentone/docs/win/online-truedbgrid/) properties are **True**, the [ButtonText](/componentone/docs/win/online-truedbgrid/) property takes precedence.

As with the default in-cell button, set the column's [ButtonAlways](/componentone/docs/win/online-truedbgrid/) property to **True** to force all of its cells to be displayed as command buttons. Only the current cell is drawn with a focus rectangle, however:

![](https://cdn.mescius.io/document-site-files/images/a1b176e5-6638-4b1f-a786-e41a817558bb/images/all-buttons-first-column.png)

## Detecting In-Cell Button Clicks

The [ButtonClick](/componentone/docs/win/online-truedbgrid/) event is provided so that code can respond when the user clicks the in-cell button. Its syntax is as follows:

```csharp
private void C1TrueDBGrid1_ButtonClick( object sender,  C1.Win.C1TrueDBGrid.ColEventArgs e)
```

In-cell buttons always fire this event when clicked, regardless of whether they were enabled by the [Button](/componentone/docs/win/online-truedbgrid/) or [ButtonText](/componentone/docs/win/online-truedbgrid/) properties. An example of the [ButtonClick](/componentone/docs/win/online-truedbgrid/) event was presented earlier in the section [Working with Text](/componentone/docs/win/online-truedbgrid/cells/cell-editing#working-with-text).

## Customizing the In-Cell Button Bitmap

By default, **True DBGrid for WinForms** uses a down arrow for the in-cell button. ![asda](https://cdn.mescius.io/document-site-files/images/a1b176e5-6638-4b1f-a786-e41a817558bb/images/image12_4.png)

However, the button bitmap can be changed for a [C1DisplayColumn](/componentone/docs/win/online-truedbgrid/) object at design time by setting the [ButtonPicture](/componentone/docs/win/online-truedbgrid/) property in code:

```csharp
this.c1TrueDBGrid1.Columns[0].ButtonPicture = System.Drawing.Image.FromFile("dollar.bmp");
```

The grid automatically draws the edges corresponding to the button's up/down states as appropriate, so only the interior image of the button needs to be provided.

![](https://cdn.mescius.io/document-site-files/images/a1b176e5-6638-4b1f-a786-e41a817558bb/images/dollar-firstcolumn.png)