Retrieves the handle of the first visible item in control.
Type | Description | |||
HITEM | A long expression that indicates the item's handle that indicates the first visible item. |
Use the FirstVisibleItem, NextVisibleItem and IsItemVisible properties to get the items that fit the client area. Use the NextVisibleItem property to get the next visible item. Use the IsVisibleItem property to check whether an item fits the control's client area. Use the RootItem property to get the first visible item in the list. The NextSiblingItem property retrieves the next sibling of the item in the parent's child list. Use the PrevVisibleItem property to retrieve the previous visible item.
The following VB sample enumerates the items that fit the control's client area:
Dim h As HITEM Dim i As Long, j As Long, nCols As Long nCols = Grid1.Columns.Count With Grid1.Items h = .FirstVisibleItem While Not (h = 0) And .IsItemVisible(h) Dim s As String s = "" For j = 0 To nCols - 1 s = s + .CellValue(h, j) + Chr(9) Next Debug.Print s h = .NextVisibleItem(h) Wend End With
The following VB sample enumerates the visible items in the control as they are displayed ( sorted ):
With Grid1.Items Dim h As HITEM h = .RootItem(0) While Not h = 0 Debug.Print .CellValue(h, 0) h = .NextVisibleItem(h) Wend End With
The following VB sample enumerates the items in the control as they are displayed ( sorted ):. For instance, the sample lists the child items of items that are collapsed too:
With Grid1.Items Dim h As HITEM h = .RootItem(0) While Not h = 0 Debug.Print .CellValue(h, 0) h = .NextSiblingItem(h) Wend End With
The following C++ sample enumerates the items that fit the control's client area:
#include "Items.h" CItems items = m_grid.GetItems(); long hItem = items.GetFirstVisibleItem(); COleVariant vtMissing; V_VT( &vtMissing ) = VT_ERROR; while ( hItem && items.GetIsItemVisible( hItem, vtMissing ) ) { OutputDebugString( V2S( &items.GetCellValue( COleVariant( hItem ), COleVariant( long(0) ) ) ) ); hItem = items.GetNextVisibleItem( hItem ); }
where the V2S function converts a VARIANT value to a string expression and looks like:
static CString V2S( VARIANT* pv, LPCTSTR szDefault = _T("") ) { if ( pv ) { if ( pv->vt == VT_ERROR ) return szDefault; COleVariant vt; vt.ChangeType( VT_BSTR, pv ); return V_BSTR( &vt ); } return szDefault; }
The following VB.NET sample enumerates the items that fit the control's client area:
With AxGrid1.Items Dim hItem As Integer = .FirstVisibleItem While Not (hItem = 0) If (.IsItemVisible(hItem)) Then Debug.Print(.CellCaption(hItem, 0)) hItem = .NextVisibleItem(hItem) Else Exit While End If End While End With
The following C# sample enumerates the items that fit the control's client area:
EXGRIDLib.Items items = axGrid1.Items; int hItem = items.FirstVisibleItem; while ((hItem != 0) && (items.get_IsItemVisible(hItem, null))) { object strCaption = items.get_CellCaption(hItem, 0); System.Diagnostics.Debug.WriteLine(strCaption != null ? strCaption.ToString() : ""); hItem = items.get_NextVisibleItem(hItem); }
The following VFP sample enumerates the items that fit the control's client area:
with thisform.Grid1.Items .DefaultItem = .FirstVisibleItem do while ( ( .DefaultItem <> 0 ) and ( .IsItemVisible( 0 ) ) ) wait window .CellCaption( 0, 0 ) .DefaultItem = .NextVisibleItem( 0 ) enddo endwith