property Items.LockedItem (Alignment as VAlignmentEnum, Index as Long) as HITEM
Retrieves the handle of the locked item.

 TypeDescription 
   Alignment as VAlignmentEnum A VAlignmentEnum expression that indicates whether the locked item requested is on the top or bottom side of the control.  
   Index as Long A long expression that indicates the position of item being requested.  
   HITEM A long expression that indicates the handle of the locked item  
A locked or fixed item is always displayed on the top or bottom side of the control no matter if the control's list is scrolled up or down. Use the LockedItem property to access a locked item by its position. Use the LockedItemCount property to add or remove items fixed/locked to the top or bottom side of the control. Use the ShowLockedItems property to show or hide the locked items. Use the IsItemLocked property to check whether an item is locked or unlocked. Use the CellValue property to specify the cell's caption. Use the InsertControlItem property to assign an ActiveX control to a locked item only. Use the DividerItem property to merge all cells in the item. Use the MergeCells property to merge cells. Use the SplitCell property to split a cell. 

The following VB sample adds an item fixed to the top side of the control:

With Grid1
    .BeginUpdate
    .ShowLockedItems = True
    If .Columns.Count > 0 Then
        With .Items
            Dim h As EXGRIDLibCtl.HITEM
            .LockedItemCount(exTop) = 1
            h = .LockedItem(exTop, 0)
            .CellValue(h, 0) = "This is an item <b>fixed</b> to the top side of the control."
            .CellValueFormat(h, 0) = exHTML
            .ItemHeight(h) = 24
            .ItemDivider(h) = 0
            .ItemDividerLine(h) = DoubleDotLine
        End With
    End If
    .EndUpdate
End With

By default, the locked items are not editable when user clicks a cell, because they are not focusable, and so a locked item can't be selected. The ItemFromPoint property gets the cell from the point. Although, the locked item can be edited using the Edit method when user clicks a cell by using a code like follows:

Private Sub Grid1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    With Grid1
        If Button = 1 Then
            Dim h As EXGRIDLibCtl.HITEM, c As Long, hit As EXGRIDLibCtl.HitTestInfoEnum
            h = .ItemFromPoint(X / Screen.TwipsPerPixelX, Y / Screen.TwipsPerPixelY, c, hit)
            If Not h = 0 Then
                If (.Items.IsItemLocked(h)) Then
                    If (.Editing = 0) Then
                        .FocusColumnIndex = c
                        .Edit h
                    End If
                End If
            End If
        End If
    End With
End Sub

The sample has effect only if the cell has an editor assigned. Use the CellEditor or Editor property to assign an editor to a cell or to its column. The following sample assigns an text box editor to a locked item:

With Grid1.Items
    With .CellEditor(.LockedItem(exTop, 0), 0)
        .EditType = EditType
    End With
End With

The following C++ sample adds a locked item, and assigns a text box editor to the locked cell:

m_grid.BeginUpdate();
m_grid.SetShowLockedItems( TRUE );
if ( m_grid.GetColumns().GetCount() > 0 )
{
	CItems items = m_grid.GetItems();
	items.SetLockedItemCount( 0, 1 );
	long hItem = items.GetLockedItem( 0, 0 );
	COleVariant vtItem( hItem ), vtColumn( (long) 0 );
	items.SetCellValue( vtItem, vtColumn, COleVariant( "This is an item <b>fixed</b> to the top side of the control." ) );
	items.SetCellValueFormat( vtItem, vtColumn, 1 );
	items.SetItemHeight( hItem, 24 );
	items.SetItemDivider( hItem, 0 );
	items.SetItemDividerLine( hItem, 2 );

	CEditor editor = items.GetCellEditor( vtItem, vtColumn );
	editor.SetEditType( 1 );
}
m_grid.EndUpdate();

The MouseUp event handler should look like follows:

void OnMouseUpGrid1(short Button, short Shift, long X, long Y) 
{
	if ( Button == 1 )
	{
		long c = 0, hit = 0, hItem = m_grid.GetItemFromPoint( X, Y, &c, &hit );
		if ( hItem )
		{
			CItems items = m_grid.GetItems();
			if ( items.GetIsItemLocked( hItem ) )
				if ( m_grid.GetEditing() == 0 )
				{
					m_grid.SetFocusColumnIndex( c );
					m_grid.Edit( COleVariant( hItem ) );
				}
		}
	}
}

The C++ code needs the following declarations:

#include "Items.h"
#include "Columns.h"
#include "Editor.h"

The following VB.NET sample adds an item that's locked to the top side of the control:

With AxGrid1
    .BeginUpdate()
    With .Items
        .LockedItemCount(EXGRIDLib.VAlignmentEnum.exTop) = 1
        Dim i As Integer
        i = .LockedItem(EXGRIDLib.VAlignmentEnum.exTop, 0)
        .CellValue(i, 0) = "<b>locked</b> item"
        .CellValueFormat(i, 0) = EXGRIDLib.ValueFormatEnum.exHTML
    End With
    .EndUpdate()
End With

The following C# sample adds an item that's locked to the top side of the control:

axGrid1.BeginUpdate();
EXGRIDLib.Items items = axGrid1.Items;
items.set_LockedItemCount(EXGRIDLib.VAlignmentEnum.exTop, 1);
int i = items.get_LockedItem(EXGRIDLib.VAlignmentEnum.exTop, 0);
items.set_CellValue(i, 0, "<b>locked</b> item");
items.set_CellValueFormat(i, 0, EXGRIDLib.ValueFormatEnum.exHTML);
axGrid1.EndUpdate();

The following VFP sample adds an item that's locked to the top side of the control:

with thisform.Grid1
	.BeginUpdate()
		With .Items
			.LockedItemCount(0) = 1
			.DefaultItem = .LockedItem(0, 0)
			.CellValue(0, 0) = "<b>locked</b> item"
			.CellValueFormat(0, 0) = 1 && EXGRIDLib.ValueFormatEnum.exHTML
		EndWith
	.EndUpdate()
endwith
 

Send comments on this topic.
© 1999-2008 Exontrol Inc, Software. All rights reserved.