Version

Key Property (ListToolItem)

Returns or sets a value that uniquely identifies an object in a collection.
Syntax
'Declaration
 
Public Overrides Property Key As String
public override string Key {get; set;}
Remarks

The Key property is a unique, user-defined object identification string that can be used interchangeably with the Index of an object when accessing it through code. If you attempt to assign a value to the Key property is not unique in the collection, an error will occur.

The value of the Index property of an object can change when objects in the collection are reordered, such as when you add or remove objects. If you expect the Index property to change dynamically, refer to objects in a collection using the Key property. In addition, you can use the Key property to make your program "self-documenting" by assigning meaningful names to the objects in a collection.

You can set the Key property when you use the Add method to add an object to a collection. In some instances, the Key property of an object may be blank if that object does not appear in a collection.

Also, note that the uniqueness of keys is only enforced when the Key property is set to a value. If a collection supports objects with blank keys, that collection may contain multiple objects that whose Key property is empty. In that case, you must use Index property to differentiate between the objects that have blank keys.

Example
The following code demonstrates how to create a main menu bar and a typical 'File' menu that contains a file MRU list. The MRU list is created using a ListTool. Also shown is how to process a ToolClick event for the MRU List's ListTool.

Imports System.Diagnostics
Imports Infragistics.Win
Imports Infragistics.Win.UltraWinToolbars

	Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click

		' ----------------------------------------------------------------------------
		' Create a PopupMenuTool.
		Dim fileMenu As New PopupMenuTool("FileMenu")

		' Always add new tools to the UltraToolbarManager's root tools collection
		' before adding them to menus or toolbars.
		Me.UltraToolbarsManager1.Tools.Add(fileMenu)


		' Set some properties on the Popup menu
		fileMenu.SharedProps.Caption = "&File"


		' ----------------------------------------------------------------------------
		' Create the usual File menu tools.
		Dim newTool As New ButtonTool("New")
		Dim openTool As New ButtonTool("Open")
		Dim closeTool As New ButtonTool("Close")
		Dim saveTool As New ButtonTool("Save")
		Dim saveAsTool As New ButtonTool("SaveAs")
		Dim printTool As New ButtonTool("Print")
		Dim printPreviewTool As New ButtonTool("PrintPreview")
		Dim fileMruListTool As New ListTool("FileMRUList")
		Dim exitTool As New ButtonTool("Exit")

		' Set some properties on the tools.
		newTool.SharedProps.Caption = "&New"
		newTool.SharedProps.AppearancesSmall.Appearance.Image = Bitmap.FromHicon(SystemIcons.Warning.Handle)
		openTool.SharedProps.Caption = "&Open"
		openTool.SharedProps.AppearancesSmall.Appearance.Image = Bitmap.FromHicon(SystemIcons.Application.Handle)
		closeTool.SharedProps.Caption = "&Close"
		closeTool.SharedProps.AppearancesSmall.Appearance.Image = Bitmap.FromHicon(SystemIcons.Error.Handle)
		saveTool.SharedProps.Caption = "&Save"
		saveTool.SharedProps.AppearancesSmall.Appearance.Image = Bitmap.FromHicon(SystemIcons.Information.Handle)
		saveAsTool.SharedProps.Caption = "Save &As"
		saveAsTool.SharedProps.AppearancesSmall.Appearance.Image = Bitmap.FromHicon(SystemIcons.WinLogo.Handle)
		printTool.SharedProps.Caption = "&Print"
		printTool.SharedProps.AppearancesSmall.Appearance.Image = Bitmap.FromHicon(SystemIcons.Hand.Handle)
		printPreviewTool.SharedProps.Caption = "Print Pre&view"
		printPreviewTool.SharedProps.AppearancesSmall.Appearance.Image = Bitmap.FromHicon(SystemIcons.Question.Handle)
		fileMruListTool.DisplayCheckmark = False
		fileMruListTool.MaxItemsToDisplay = 10
		fileMruListTool.MoreItemsText = "More files..."

		' Add some MRU entries to the List tool.  The List tool is a special tool that
		' can only be placed on a menu (not on a toolbar).  Unlike other tools which
		' result in a single menuitem being displayed on a menu, the ListTool will cause
		' a menuitem to be displayed for each ListToolItem in the list.
		Dim mruListItem As ListToolItem

		mruListItem = fileMruListTool.ListToolItems.Add("file1", "C:\\Temp\\bootlog1.txt")
		mruListItem.Value = "C:\\Temp\\bootlog1.txt"
		mruListItem = fileMruListTool.ListToolItems.Add("file2", "C:\\Temp\\bootlog2.txt")
		mruListItem.Value = "C:\\Temp\\bootlog2.txt"
		mruListItem = fileMruListTool.ListToolItems.Add("file3", "C:\\Temp\\bootlog3.txt")
		mruListItem.Value = "C:\\Temp\\bootlog3.txt"
		mruListItem = fileMruListTool.ListToolItems.Add("file4", "C:\\Temp\\bootlog4.txt")
		mruListItem.Value = "C:\\Temp\\bootlog4.txt"
		mruListItem = fileMruListTool.ListToolItems.Add("file5", "C:\\Temp\\bootlog5.txt")
		mruListItem.Value = "C:\\Temp\\bootlog5.txt"

		exitTool.SharedProps.Caption = "E&xit"
		exitTool.SharedProps.AppearancesSmall.Appearance.Image = Bitmap.FromHicon(SystemIcons.Warning.Handle)

		' Always add new tools to the UltraToolbarManager's root tools collection
		' before adding them to menus or toolbars.
		Me.UltraToolbarsManager1.Tools.AddRange(New ToolBase() {newTool, openTool, closeTool, saveTool, saveAsTool, printTool, printPreviewTool, fileMruListTool, exitTool})

		' Add the tools to the popup menu
		fileMenu.Tools.AddToolRange(New String() {"New", "Open", "Close", "Save", "SaveAs", "Print", "PrintPreview", "FileMRUList", "Exit"})

		' Add some separators between the tools.
		fileMenu.Tools("Save").InstanceProps.IsFirstInGroup = True
		fileMenu.Tools("Print").InstanceProps.IsFirstInGroup = True
		fileMenu.Tools("FileMRUList").InstanceProps.IsFirstInGroup = True
		fileMenu.Tools("Exit").InstanceProps.IsFirstInGroup = True


		' ----------------------------------------------------------------------------
		' Create a main menu bar and add the popup menu to it.
		Me.UltraToolbarsManager1.Toolbars.AddToolbar("MyMainMenuBar")

		' Make the toolbar a main menu bar.
		Me.UltraToolbarsManager1.Toolbars("MyMainMenuBar").IsMainMenuBar = True

		Me.UltraToolbarsManager1.Toolbars("MyMainMenuBar").Tools.AddTool("FileMenu")

	End Sub

	Private Sub UltraToolbarsManager1_ToolClick(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinToolbars.ToolClickEventArgs) Handles UltraToolbarsManager2.ToolClick

		Select Case (e.Tool.Key)
			Case "FileMRUList"
				Debug.WriteLine("The FileMRUList item with a key of '" + e.ListToolItem.Key + "', text of '" + e.ListToolItem.Text + "', Index of '" + e.ListToolItem.Index + "' and Value of '" + e.ListToolItem.Value.ToString() + "' was clicked.")

		End Select

	End Sub
using System.Diagnostics;
using Infragistics.Win;
using Infragistics.Win.UltraWinToolbars;

		private void button6_Click(object sender, System.EventArgs e)
		{

			// ----------------------------------------------------------------------------
			// Create a PopupMenuTool.
				PopupMenuTool fileMenu = new PopupMenuTool("FileMenu");

				// Always add new tools to the UltraToolbarManager's root tools collection
				// before adding them to menus or toolbars.
				this.ultraToolbarsManager1.Tools.Add(fileMenu);


				// Set some properties on the Popup menu
				fileMenu.SharedProps.Caption = "&File";


			// ----------------------------------------------------------------------------
			// Create the usual File menu tools.
				ButtonTool newTool		= new ButtonTool("New");
				ButtonTool openTool		= new ButtonTool("Open");
				ButtonTool closeTool		= new ButtonTool("Close");
				ButtonTool saveTool		= new ButtonTool("Save");
				ButtonTool saveAsTool		= new ButtonTool("SaveAs");
				ButtonTool printTool		= new ButtonTool("Print");
				ButtonTool printPreviewTool 	= new ButtonTool("PrintPreview");
				ListTool   fileMruListTool	= new ListTool("FileMRUList");
				ButtonTool exitTool		= new ButtonTool("Exit");

				// Set some properties on the tools.
				newTool.SharedProps.Caption					= "&New";
				newTool.SharedProps.AppearancesSmall.Appearance.Image	= Bitmap.FromHicon(SystemIcons.Warning.Handle);
				openTool.SharedProps.Caption					= "&Open";
				openTool.SharedProps.AppearancesSmall.Appearance.Image	= Bitmap.FromHicon(SystemIcons.Application.Handle);
				closeTool.SharedProps.Caption					= "&Close";
				closeTool.SharedProps.AppearancesSmall.Appearance.Image	= Bitmap.FromHicon(SystemIcons.Error.Handle);
				saveTool.SharedProps.Caption					= "&Save";
				saveTool.SharedProps.AppearancesSmall.Appearance.Image	= Bitmap.FromHicon(SystemIcons.Information.Handle);
				saveAsTool.SharedProps.Caption				= "Save &As";
				saveAsTool.SharedProps.AppearancesSmall.Appearance.Image= Bitmap.FromHicon(SystemIcons.WinLogo.Handle);
				printTool.SharedProps.Caption					= "&Print";
				printTool.SharedProps.AppearancesSmall.Appearance.Image	= Bitmap.FromHicon(SystemIcons.Hand.Handle);
				printPreviewTool.SharedProps.Caption				= "Print Pre&view";
				printPreviewTool.SharedProps.AppearancesSmall.Appearance.Image= Bitmap.FromHicon(SystemIcons.Question.Handle);
				fileMruListTool.DisplayCheckmark				= false;
				fileMruListTool.MaxItemsToDisplay				= 10;
				fileMruListTool.MoreItemsText					= "More files...";

				// Add some MRU entries to the List tool.  The List tool is a special tool that
				// can only be placed on a menu (not on a toolbar).  Unlike other tools which
				// result in a single menuitem being displayed on a menu, the ListTool will cause
				// a menuitem to be displayed for each ListToolItem in the list.
				ListToolItem mruListItem = null;

				mruListItem = fileMruListTool.ListToolItems.Add("file1", "C:\\Temp\\bootlog1.txt");
				mruListItem.Value = "C:\\Temp\\bootlog1.txt";
				mruListItem = fileMruListTool.ListToolItems.Add("file2", "C:\\Temp\\bootlog2.txt");
				mruListItem.Value = "C:\\Temp\\bootlog2.txt";
				mruListItem = fileMruListTool.ListToolItems.Add("file3", "C:\\Temp\\bootlog3.txt");
				mruListItem.Value = "C:\\Temp\\bootlog3.txt";
				mruListItem = fileMruListTool.ListToolItems.Add("file4", "C:\\Temp\\bootlog4.txt");
				mruListItem.Value = "C:\\Temp\\bootlog4.txt";
				mruListItem = fileMruListTool.ListToolItems.Add("file5", "C:\\Temp\\bootlog5.txt");
				mruListItem.Value = "C:\\Temp\\bootlog5.txt";

				exitTool.SharedProps.Caption					= "E&xit";
				exitTool.SharedProps.AppearancesSmall.Appearance.Image	= Bitmap.FromHicon(SystemIcons.Warning.Handle);

				// Always add new tools to the UltraToolbarManager's root tools collection
				// before adding them to menus or toolbars.
				this.ultraToolbarsManager1.Tools.AddRange(new ToolBase [] {newTool, openTool, closeTool, saveTool, saveAsTool, printTool, printPreviewTool, fileMruListTool, exitTool} );

				// Add the tools to the popup menu
				fileMenu.Tools.AddToolRange(new string [] {"New", "Open", "Close", "Save", "SaveAs", "Print", "PrintPreview", "FileMRUList", "Exit"} );

				// Add some separators between the tools.
				fileMenu.Tools["Save"].InstanceProps.IsFirstInGroup		= true;
				fileMenu.Tools["Print"].InstanceProps.IsFirstInGroup		= true;
				fileMenu.Tools["FileMRUList"].InstanceProps.IsFirstInGroup	= true;
				fileMenu.Tools["Exit"].InstanceProps.IsFirstInGroup		= true;


			// ----------------------------------------------------------------------------
			// Create a main menu bar and add the popup menu to it.
				this.ultraToolbarsManager1.Toolbars.AddToolbar("MyMainMenuBar");

				// Make the toolbar a main menu bar.
				this.ultraToolbarsManager1.Toolbars["MyMainMenuBar"].IsMainMenuBar = true;

				this.ultraToolbarsManager1.Toolbars["MyMainMenuBar"].Tools.AddTool("FileMenu");

		}

		private void ultraToolbarsManager1_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
		{

			switch (e.Tool.Key)
			{
				case "FileMRUList":
					Debug.WriteLine("The FileMRUList item with a key of '" + e.ListToolItem.Key + "', text of '" + e.ListToolItem.Text + "', Index of '" + e.ListToolItem.Index + "' and Value of '" + e.ListToolItem.Value.ToString() + "' was clicked.");
					break;
			}

		}
Requirements

Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Server 2012, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also