property Items.CellValue([Item as Variant], [ColIndex as Variant]) as Variant

Specifies the cell's value.

   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.  If the Item parameter is missing or it is zero ( 0 ), the ColIndex parameter is the handle of the cell being accessed.  
   Variant A variant expression that indicates the cell's value or content. The cell's value supports built-in HTML format if the CellValueFormat property is exHTML.  

Use the CellValue property to specify the value or the content for cells in the second, third columns and so on. The CellValueFormat property indicates the way the cell displays its content. The Def(exCellValueFormat) property indicates the format for all cells within the column. 

The cell shows its text based on the CellValueFormat property as follows:

The CellValue property of the cell is being shown as:

In other words, all cells applies the format of the FormatColumn property, excepts the cells with the FormatCell property being set. If the cell belongs to a column with the FireFormatColumn property on True, the Value parameter of the FormatColumn event shows the newly caption for the cell to be shown.

The Change event is called when the user changes the CellValue property. Use the CellData property to associate an user data to a cell. The CellSortData property specifies the value being sorted if the SortType property is SortCellData or SortCellDataString. The AddItem or InsertItem  method may specify the value for the first cell. Use the LockedItemCount property to lock or unlock items to the top or bottom side of the control. Use the ItemCell property to get the cell's handle based on the item and the column. Use the CellItem property to get the handle of the item that's the owner of the cell. Use the SplitCell property to split a cell. If the CauseValidateValue property is True, the control fires the ValidateValue property when the user changes the CellValue property. Use the AddItem method to add new predefined values to a drop down list editor. Use the CellEditor property to assign an editor to a single cell. Use the Editor property to assign the same editor to all cells in the column. Use the Add method to add new columns to the control. Use the ConditionalFormats method to apply formats to a cell or range of cells, and have that formatting change depending on the value of the cell or the value of a formula.

The following VB sample displays an HTML cell on multiple lines:

With Grid1.Items
        Dim h As HITEM
        h = .AddItem("Cell 1")
        .CellValue(h, 1) = "<r><dotline><b>HTML support</b><br>This is a bit of text where built-in <b>HTML</b> support is enabled."
        .CellValueFormat(h, 1) = exHTML
        .CellSingleLine(h, 1) = False
        .CellEditorVisible(h, 1) = False
End With

The following C++ changes the value of the focused cell:

#include "Items.h"
CItems items = m_grid.GetItems();
COleVariant vtItem( items.GetFocusItem() ), vtColumn( long(m_grid.GetFocusColumnIndex()) );
items.SetCellValue( vtItem, vtColumn, COleVariant("new value") );

The following VB.NET changes the value of the focused cell:

With AxGrid1.Items
    .CellValue(.FocusItem, AxGrid1.FocusColumnIndex) = "new value"
End With

The following C# changes the value of the focused cell:

axGrid1.Items.set_CellValue(axGrid1.Items.FocusItem, axGrid1.FocusColumnIndex, "new value");

The following VFP changes the value of the focused cell:

with thisform.Grid1.Items
	.DefaultItem = .FocusItem
	.CellValue(0,thisform.Grid1.FocusColumnIndex) = "new value"

You may include strings like [m], [m], [180], ml, or m, m, and so on. Copy the symbol from this page, and paste to your cell.

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

Send comments on this topic.
1999-2017 Exontrol.COM, Software. All rights reserved.