property Columns.Item (Index as Variant) as Column
Returns a specific Column of the Columns collection.

   Index as Variant A long expression that indicates the column's index, or a string expression that indicates the column's caption or column's key.  
   Column A Column object being accessed.  
Use the Item property to access to a specific column.  The Count property counts the columns in the control. Use the Columns property to access the control's Columns collection. The SortBarColumn / SortBarColumnsCount properties can be used to enumerate the columns in the control's sort bar. The Visible property indicates whether the column is visible or hidden. The Position property specifies the position of the column. The user can change the column's position by drag and drop, so the position of the column can be changed at runtime. Instead the Index property is a read only property that gives the index of the column in the collection.  

The following VB6 sample enumerates the visible columns as they are displayed:

Private Sub enumColumns(ByVal g As EXGRIDLibCtl.Grid)
    Dim cArray() As EXGRIDLibCtl.Column
    With g
        ReDim Preserve cArray(.Columns.Count)
        For Each c In .Columns
            If (c.Visible) Then
                Set cArray(c.Position) = c
            End If
    End With
    For Each c In cArray
        If Not c Is Nothing Then
            Debug.Print c.Caption & "(" & c.Index & ")"
        End If
End Sub

The Item property is the default property of the Columns object so the following statements are equivalents:

Grid1.Columns.Item ("Freight")
Grid1.Columns ("Freight")

The following VB sample enumerates the columns in the control:

For i = 0 To Grid1.Columns.Count - 1
    Debug.Print Grid1.Columns(i).Caption

The following VC sample enumerates the columns in the control:

#include "Columns.h"
#include "Column.h"
CColumns columns = m_grid.GetColumns();
for ( long i = 0; i < columns.GetCount(); i++ )
	CColumn column = columns.GetItem( COleVariant( i ) );
	OutputDebugString( column.GetCaption() );

The following VB.NET sample enumerates the columns in the control:

With AxGrid1.Columns
    Dim i As Integer
    For i = 0 To .Count - 1
End With

The following C# sample enumerates the columns in the control:

EXGRIDLib.Columns columns =axGrid1.Columns;
for ( int i = 0; i < columns.Count; i++ )
	EXGRIDLib.Column column = columns[i];
	System.Diagnostics.Debug.WriteLine( column.Caption );

The following VFP sample enumerates the columns in the control:

with thisform.Grid1.Columns
	for i = 0 to .Count - 1
		wait window nowait .Item(i).Caption


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