Retrieves or sets a value indicating whether the cell has an
associated push button.
Type | Description | |||
Item as Variant | A long expression that indicates the item's handle. | |||
ColIndex as Variant | A long expression that indicates the cell's handle or the column's index, a string expression that indicates the column's caption or the column's key. | |||
Boolean | A boolean expression that indicates whether the cell contains a button. |
Each time when user clicks a cell that has CellHasButton property to True, the control fires ButtonClick event. The caption of the push button is defined by the CellValue property. Use the Def property to assign buttons to all cells in the column. Use the CellButtonAutoWidth property to specify whether the buttons fit the cell's content. Use the CellEditor property to assign an editor to a cell. Use the Editor property to assign the same editor to all cells in the column. Use the AddButton method to add a new button to an editor. If you need multiple buttons inside the same cell, you can split the cell in multiple pieces and add a button to each piece. Use the SplitCell property to split a cell. Use the Background(exCellButtonUp) or Background(exCellButtonDown) property to change the visual appearance for the buttons in the control.
The following VB sample adds a header row column:
With Grid1.Columns.Add("H") .Def(exCellHasButton) = True .Position = 0 .AllowDragging = False .HeaderAlignment = CenterAlignment .Width = 16 End With
The following VB sample assigns a button for each cell in the first column, as soon as a new item is inserted:
Private Sub Grid1_AddItem(ByVal Item As EXGRIDLibCtl.HITEM) Grid1.Items.CellHasButton(Item, 0) = True End Sub Private Sub Grid1_ButtonClick(ByVal Item As EXGRIDLibCtl.HITEM, ByVal ColIndex As Long) MsgBox "The cell of button type has been clicked." End Sub
The following VB sample assigns a button to the focused cell:
With Grid1.Items .CellHasButton(.FocusItem, Grid1.FocusColumnIndex) = True End With
The following VB sample adds four buttons in the same cell:
With Grid1.Items Dim h As HITEM h = .FirstVisibleItem() .CellValue(h, 0) = "B1" .CellHasButton(h, 0) = True f = .SplitCell(h, 0) .CellValue(, f) = "B2" .CellHasButton(, f) = True f = .SplitCell(, f) .CellValue(, f) = "B3" .CellHasButton(, f) = True f = .SplitCell(, f) .CellValue(, f) = "B4" .CellHasButton(, f) = True End With
The following C++ sample adds a header row column:
#include "Column.h" #include "Columns.h" CColumns columns = m_grid.GetColumns(); CColumn column( V_DISPATCH( &columns.Add("H") ) ); column.SetHeaderAlignment( 1 ); column.SetDef(2, COleVariant( VARIANT_TRUE ) ); column.SetPosition( 0 ); column.SetWidth( 16 ); column.SetAllowDragging( FALSE );
The following C++ sample assigns a button to the focused cell:
#include "Items.h" CItems items = m_grid.GetItems(); items.SetCellHasButton( COleVariant( items.GetFocusItem() ), COleVariant( (long)m_grid.GetFocusColumnIndex() ), TRUE );
The following VB.NET sample adds a header row column:
With AxGrid1.Columns.Add("H") .Def(EXGRIDLib.DefColumnEnum.exCellHasButton) = True .Position = 0 .AllowDragging = False .HeaderAlignment = EXGRIDLib.AlignmentEnum.CenterAlignment .Width = 16 End With
The following VB.NET sample assigns a button to the focused cell:
With AxGrid1.Items .CellHasButton(.FocusItem, AxGrid1.FocusColumnIndex) = True End With
The following C# sample adds a header row column:
EXGRIDLib.Columns columns = axGrid1.Columns; EXGRIDLib.Column column = columns.Add("H") as EXGRIDLib.Column; column.set_Def(EXGRIDLib.DefColumnEnum.exCellHasButton, true); column.Position = 0; column.HeaderAlignment = EXGRIDLib.AlignmentEnum.CenterAlignment; column.AllowDragging = false; column.Width = 16;
The following C# sample assigns a button to the focused cell:
axGrid1.Items.set_CellHasButton(axGrid1.Items.FocusItem, axGrid1.FocusColumnIndex, true);
The following VFP sample adds a header row column:
with thisform.Grid1.Columns.Add("H") .Position = 0 .Def(2) = .t. .AllowDragging = .f. .Width = 16 endwith
The following VFP sample assigns a button to the focused cell:
with thisform.Grid1.Items .DefaultItem = .FocusItem .CellHasButton(0,thisform.Grid1.FocusColumnIndex) = .t. endwith
Note: The intersection of an item with a column defines a cell. Each cell is uniquely represented by its handle. The cell's handle is of HCELL type, that's equivalent with a long type. All properties of Items object that have two parameters Item and ColIndex, refer a cell.
The following lines are equivalents and each of them changes the bold font attribute of the first cell on the first item.
With Grid1 .Items.CellBold(, .Items.ItemCell(.Items(0), 0)) = True .Items.CellBold(.Items(0), 0) = True .Items.CellBold(.Items(0)) = True .Items.CellBold(.Items.ItemByIndex(0)) = True .Items.CellBold(.Items.ItemByIndex(0), 0) = True .Items.CellBold(.Items(0), Grid1.Columns(0).Caption) = True End With