Type | Description | |||
Item as Variant | A long expression that indicates the handle of the item where the cell is, or 0. If the Item parameter is 0, the ColIndex parameter must indicate the handle of the cell. | |||
ColIndex as Variant | A long expression that indicates the index of the column where a cell is divided, or a long expression that indicates the handle of the cell being divided, if the Item parameter is missing or it is zero. | |||
Long | A long expression that indicates the width of the cell. |
The CellWidth property specifies the width of the cell, where the cell is divided in two or multiple (inner) cells like follows:
By default, the CellWidth property is -1, and so when the user splits a cell the inner cell takes the right half of the area occupied by the master cell.
The following VB sample specifies that the master cell should have 32 pixels, and the other two inner cells get the same width:
With Grid1.Items Dim h As HITEM, f As HCELL h = .FirstVisibleItem .CellWidth(h, 0) = 32 f = .ItemCell(h, 0) f = .SplitCell(, f) f = .SplitCell(, f) End With
The following VB sample specifies that the inner cells should have 32 pixels:
With Grid1.Items Dim h As HITEM, f As HCELL h = .FirstVisibleItem f = .SplitCell(h, 0) .CellWidth(, f) = 32 End With
The following VB sample adds an inner cell to the focused cell with 48 pixels width:
Grid1.BeginUpdate With Grid1.Items Dim h As Long h = .SplitCell(.FocusItem, 0) .CellBackColor(, h) = vbBlack .CellForeColor(, h) = vbWhite .CellHAlignment(, h) = CenterAlignment .CellValue(, h) = "inner" .CellWidth(, h) = 48 End With Grid1.EndUpdate
The following C++ sample adds an inner cell to the focused cell with 48 pixels width:
#include "Items.h" m_grid.BeginUpdate(); CItems items = m_grid.GetItems(); COleVariant vtItem( items.GetFocusItem() ), vtColumn( long(0) ), vtMissing; V_VT( &vtMissing ) = VT_ERROR; COleVariant vtInner = items.GetSplitCell( vtItem, vtColumn ); items.SetCellWidth( vtMissing, vtInner, 48 ); items.SetCellBackColor( vtMissing, vtInner, 0 ); items.SetCellForeColor( vtMissing, vtInner, RGB(255,255,255) ); items.SetCellValue( vtMissing, vtInner, COleVariant("inner") ); items.SetCellHAlignment( vtMissing, vtInner, 1 ); m_grid.EndUpdate();
The following VB.NET sample adds an inner cell to the focused cell with 48 pixels width:
With AxGrid1 .BeginUpdate() With .Items Dim iInner As Integer iInner = .SplitCell(.FocusItem, 0) .CellValue(, iInner) = "inner" .CellHAlignment(, iInner) = EXGRIDLib.AlignmentEnum.CenterAlignment .CellWidth(, iInner) = 48 .CellBackColor(, iInner) = 0 .CellForeColor(, iInner) = ToUInt32(Color.White) End With .EndUpdate() End With
where the ToUInt32 function converts a Color expression to an OLE_COLOR expression and may look like:
Shared Function ToUInt32(ByVal c As Color) As UInt32 Dim i As Long i = c.R i = i + 256 * c.G i = i + 256 * 256 * c.B ToUInt32 = Convert.ToUInt32(i) End Function
The following C# sample adds an inner cell to the focused cell with 48 pixels width:
EXGRIDLib.Items items = axGrid1.Items; axGrid1.BeginUpdate(); object iInner = items.get_SplitCell(axGrid1.Items.FocusItem, 0); items.set_CellValue(null, iInner, "inner"); items.set_CellHAlignment(null, iInner, EXGRIDLib.AlignmentEnum.CenterAlignment); items.set_CellBackColor(null, iInner, ToUInt32(Color.Black)); items.set_CellForeColor(null, iInner, ToUInt32(Color.White)); items.set_CellWidth(null, iInner, 48); axGrid1.EndUpdate();
where the ToUInt32 function converts a Color to an OLE_COLOR expression and looks like:
private UInt32 ToUInt32(Color c) { long i; i = c.R; i = i + 256 * c.G; i = i + 256 * 256 * c.B; return Convert.ToUInt32(i); }