	/*
	 * This code sample illustrates how to select items in a listview by 
	 * taking the key pressed in a TextBox control and finding the next 
	 * item in a ListView Control whose name starts with the key pressed
	 * (n.b. This is done in a case insensitive manner)
	 * 
	 * It was written to hopefully prod the Gnome developers into adding
	 * this functionality to the Nautilus file broswer by showing how 
	 * trivially easy it would be to add such useful functionality :)
	 * 
	 * n.b. This code was written using SharpDevelop (a clone of Microsoft
	 * Visual Studio.Net) where the ListView control used to hold the object
	 * names already has the required functionality "built in".
	 * 
	 * So, to illustrate the logic involved, the code was written to make
	 * use of a TextBox controls KeyUp event.
	 * 
	 * A further thing to note is that the author is not a "native" C# coder
	 * so this code sample was actually written in VB.Net before being 
	 * converted to C# using SharpDevelops "Convert buffer from VB.Net to 
	 * C# " function. 
	 * 
	 * This being the case some of the resulting C# code may not be written 
	 * "as well as it could be" (i.e. the "goto exitForStatement" code used 
	 * for exiting loops doesn't look too good to me !)
	 * 
	 */

	private void TextBox1_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
	{
		/* Convert the key pressed to lower case  */
		string KeyPressed = e.KeyData.ToString.ToLower;

		/* If an item is selected then start the search from the next item in the 	
		 * list.  If no item is selected start the search from the beginning. */
		int CurrentIndex = 0;

		if (this.FileSystemObjectsListView.SelectedItems.Count > 0) {
			CurrentIndex = this.FileSystemObjectsListView.SelectedItems(0).Index();
		}

		/* Declare a new index with an invalid (negative) value */
		int NewIndex = -1;

		/* Use to hold the lower case verion of the first letter of an item name */
		string FirstLetterOfItemName;

		/* Start searching from the next item until we either get a match or 
		 * we reach the last item in the list */
		for (int i = (CurrentIndex + 1); i <= this.FileSystemObjectsListView.Items.Count - 1; i++) {
			/* Convert the first character of current item name to lower case */
			FirstLetterOfItemName = this.FileSystemObjectsListView.Items(i).Text.Substring(0, 1).ToLower;
			
			if (FirstLetterOfItemName.Equals(KeyPressed)) {
				/* Item found, set index and exit loop */
				NewIndex = i;

				goto exitForStatement0;
			}
		}

		 exitForStatement0: ;

		/* If new index is still -1 then we haven't found an item yet.  Restart 
		 * the search from the first item. */
		if (NewIndex == -1) {
		 	for (int i = 0; i <= CurrentIndex; i++) {
				/* Convert the first character of current item name to lower case */
				FirstLetterOfItemName = this.FileSystemObjectsListView.Items(i).Text.Substring(0, 1).ToLower;
		
				if (FirstLetterOfItemName.Equals(KeyPressed)) {
				/* Item found, set index and exit loop */
					NewIndex = i;

					goto exitForStatement1;
				}
			}
			exitForStatement1: ;
		}

		/* If NewIndex is set select the item */
		if (NewIndex > -1) {
			/* First unselect all currently selected items */
			foreach (ListViewItem Item in this.FileSystemObjectsListView.SelectedItems) {
				Item.Selected = false;
			}
	
			/* Select required item */
			this.FileSystemObjectsListView.Items(NewIndex).Selected = true;
		}
	}
