property FileType.IconIndex as Long

Indicates the icon index used to replace the default icon for files that match the FileType's pattern.

TypeDescription
Long A long expression that indicates the icon's key that replace the default icon for files that match the FileType's pattern.

Use the LoadIcons and LoadIcon properties to add new icons to the control. When you are using LoadIcon property to add a new icon, you have to use the icon's key for the IconIndex property. If you are loading a collection of icons using LoadIcons property, you have to use the index of icon into the icons collection. The Apply method applies the changes to the current list.  Use the BrowseFolderPath property to specify the path to the browsed folder. The control fires the StateChange event when the user changes the browsed path. 

The following VB sample replaces the default icon for files of BMP and JPG types with the icon:

With ExFileView1
    .LoadIcon LoadPicture("C:\Temp\sample.ico").Handle, 1234
    With .FileTypes.Add("*.bmp *.jpg")
        .IconIndex = 1234
        .Apply
    End With
End With

After running the sample the default icons for BMP and JPG files is changed like:

The following C++ sample replaces the default icon for files of BMP and JPG types:

IPictureDisp* pPicture = NULL;
if ( LoadPicture( "c:\\temp\\sample.ico", &pPicture ) )
{
	OLE_HANDLE hIcon = NULL;
	if ( CComQIPtr<IPicture> spPicture( pPicture ) )
		spPicture->get_Handle( &hIcon );
	m_fileview.LoadIcon( hIcon, 1234 );

	CFileType fileType = m_fileview.GetFileTypes().Add("*.bmp *.jpg");
	fileType.SetIconIndex( 1234 );
	fileType.Apply();
}

where the LoadPicture function loads a picture from a file, and gets the IPictureDisp interface:

#include 
BOOL LoadPicture( LPCTSTR szFileName, IPictureDisp** ppPictureDisp )
{
	BOOL bResult = FALSE;
	if ( szFileName )
	{
		OFSTRUCT of;
		HANDLE hFile = NULL;;
#ifdef _UNICODE
		USES_CONVERSION;
		if ( (hFile = (HANDLE)OpenFile( W2A(szFileName), &of, OF_READ | OF_SHARE_COMPAT)) != (HANDLE)HFILE_ERROR )
#else
		if ( (hFile = (HANDLE)OpenFile( szFileName, &of, OF_READ | OF_SHARE_COMPAT)) != (HANDLE)HFILE_ERROR )
#endif
		{
			*ppPictureDisp = NULL;
			DWORD dwHighWord = NULL, dwSizeLow = GetFileSize( hFile, &dwHighWord );
			DWORD dwFileSize = dwSizeLow;
			HRESULT hResult = NULL;
			if ( HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize) )
				if ( void* pvData = GlobalLock( hGlobal ) )
				{
					DWORD dwReadBytes = NULL;
					BOOL bRead = ReadFile( hFile, pvData, dwFileSize, &dwReadBytes, NULL );
					GlobalUnlock( hGlobal );
					if ( bRead )
					{
						CComPtr spStream;
						_ASSERTE( dwFileSize == dwReadBytes );
						if ( SUCCEEDED( CreateStreamOnHGlobal( hGlobal, TRUE, &spStream) ) )
							if ( SUCCEEDED( hResult = OleLoadPicture( spStream, 0, FALSE, IID_IPictureDisp, (void**)ppPictureDisp ) ) )
								bResult = TRUE;
					}
				}
			CloseHandle( hFile );
		}
	}
	return bResult;
}

The following VB.NET sample replaces the default icon for files of BMP and JPG types:

With AxExFileView1
    Dim spPicture As stdole.IPictureDisp = IPDH.GetIPictureDisp(Image.FromFile("c:\temp\sample.ico"))
    .LoadIcon(spPicture.Handle, 1234)
    With .FileTypes.Add("*.bmp *.jpg")
        .IconIndex = 1234
        .Apply()
    End With
End With

where the IPDH class is defined like follows:

Public Class IPDH
    Inherits System.Windows.Forms.AxHost

    Sub New()
        MyBase.New("")
    End Sub

    Public Shared Function GetIPictureDisp(ByVal image As Image) As Object
        GetIPictureDisp = AxHost.GetIPictureDispFromPicture(image)
    End Function

End Class

The following C# sample replaces the default icon for files of BMP and JPG types:

stdole.IPictureDisp spPicture = IPDH.GetIPictureDisp(Image.FromFile("c:\\temp\\sample.ico")) as stdole.IPictureDisp;
axExFileView1.LoadIcon( spPicture.Handle, 1234);
EXFILEVIEWLib.FileType fileType = axExFileView1.FileTypes.Add("*.bmp *.jpg");
fileType.IconIndex = 1234;
fileType.Apply();

where the IPDH class is defined like follows:

internal class IPDH : System.Windows.Forms.AxHost
{
	public IPDH() : base("")
	{
	}

	public static object GetIPictureDisp(System.Drawing.Image image)
	{
		return System.Windows.Forms.AxHost.GetIPictureDispFromPicture( image );
	}
}

The following VFP sample replaces the default icon for files of BMP and JPG types:

With thisform.ExFileView1
	local i
	with LoadPicture("C:\temp\sample.ico")
		i = .Handle()
	endwith
    .Object.LoadIcon(i, 1234)
    With .FileTypes.Add("*.bmp *.jpg")
        .IconIndex = 1234
        .Apply
    EndWith
EndWith
}