Click here to Skip to main content
13,090,426 members (35,339 online)
Click here to Skip to main content


165 bookmarked
Posted 13 Mar 2003

C# does Shell, Part 4

, 26 Mar 2003
This article is about the AutoComplete features enabled by windows and how to use them with C#. AutoComplete is the ability to expand strings written in an edit box. The article will develop a class for using this functionality in you applications.
using System;
using System.Runtime.InteropServices;

namespace ShellLib
	public class SourceCustomList : UCOMIEnumString
		public string[] StringList;
		private Int32 currentPosition = 0;
		/// <summary>
		/// This method retrieves the next celt items in the enumeration sequence. If there are fewer than the 
		/// requested number of elements left in the sequence, it retrieves the remaining elements. The number 
		/// of elements actually retrieved is returned through pceltFetched, unless the caller passed in NULL 
		/// for that parameter.
		/// </summary>
		public Int32 Next(
			Int32 celt,					// Number of elements being requested.
			String[] rgelt,				// Array of size celt (or larger) of the elements of interest. The 
										// type of this parameter depends on the item being enumerated. 
			out Int32 pceltFetched)		// Pointer to the number of elements actually supplied in rgelt. The Caller can pass in NULL if celt is 1. 
			pceltFetched = 0;
			while ((currentPosition <= StringList.Length-1) && (pceltFetched<celt))
				rgelt[pceltFetched] = StringList[currentPosition];
			if (pceltFetched == celt)
				return 0;	// S_OK;
				return 1;	// S_FALSE;

		/// <summary>
		/// This method skips the next specified number of elements in the enumeration sequence.
		/// </summary>
		public Int32 Skip(
			Int32 celt)					// Number of elements to be skipped. 
			currentPosition += (int)celt;
			if (currentPosition <= StringList.Length-1)
				return 0;
				return 1;

		/// <summary>
		/// This method resets the enumeration sequence to the beginning.
		/// </summary>
		public Int32 Reset()
			currentPosition = 0;
			return 0;

		/// <summary>
		/// This method creates another enumerator that contains the same enumeration state as the current one. 
		/// Using this function, a client can record a particular point in the enumeration sequence and return to 
		/// that point at a later time. The new enumerator supports the same interface as the original one.
		/// </summary>
		public void Clone(
			out UCOMIEnumString ppenum)			// Address of the IEnumString pointer variable that receives the interface 
												// pointer to the enumeration object. If the method is unsuccessful, the 
												// value of this output variable is undefined. 
			SourceCustomList clone = new SourceCustomList();
			clone.currentPosition = currentPosition;
			clone.StringList = (String[])StringList.Clone();
			ppenum = clone;



By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


About the Author

Arik Poznanski
Software Developer (Senior) Verint
Israel Israel
Arik Poznanski is a senior software developer at Verint. He completed two B.Sc. degrees in Mathematics & Computer Science, summa cum laude, from the Technion in Israel.

Arik has extensive knowledge and experience in many Microsoft technologies, including .NET with C#, WPF, Silverlight, WinForms, Interop, COM/ATL programming, C++ Win32 programming and reverse engineering (assembly, IL).

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.170813.1 | Last Updated 27 Mar 2003
Article Copyright 2003 by Arik Poznanski
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid