//=======================================================================================
//
// This source code is only intended as a supplement to existing Microsoft documentation.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
// PURPOSE.
//
// Copyright (C) Microsoft Corporation. All Rights Reserved.
//
//=======================================================================================
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Text;
namespace Microsoft.ManagementConsole.Samples
{
///
/// MmcListView class - Basic listing of icon and name in the result pane.
/// StandardVerbsListView class - Listing with some StandardVerbs enabled.
///
public class StandardVerbsListView : MmcListView
{
///
/// Constructor.
///
public StandardVerbsListView()
{
}
///
/// Define the ListView's structure and actions
///
/// status for updating the console
protected override void OnInitialize(AsyncStatus status)
{
// do default handling
base.OnInitialize(status);
// Create a set of columns for use in the list view
// Define the default column title
this.Columns[0].Title = "User";
this.Columns[0].SetWidth(300);
// Add detail column
this.Columns.Add(new MmcListViewColumn("Birthday", 200));
// Set to show all columns
this.Mode = MmcListViewMode.Report;
// Load the list with values
Refresh();
}
///
/// Manage shortcut menu for selection
///
/// status for updating the console
protected override void OnSelectionChanged(SyncStatus status)
{
if (this.SelectedNodes.Count == 0)
{
this.SelectionData.Clear();
}
else
{
this.SelectionData.Update(null, this.SelectedNodes.Count > 1, null, null);
this.SelectionData.EnabledStandardVerbs = StandardVerbs.Delete | StandardVerbs.Refresh;
// rename is only for single node
if (this.SelectedNodes.Count == 1)
{
this.SelectionData.EnabledStandardVerbs = this.SelectionData.EnabledStandardVerbs | StandardVerbs.Rename;
}
}
}
///
/// Handles Delete standard verb
///
/// synchronous status used to update console
protected override void OnDelete(SyncStatus status)
{
foreach (ResultNode cutNode in this.SelectedNodes)
{
this.ResultNodes.Remove(cutNode);
}
}
///
/// Handles Refresh standard verb
///
/// asynchronous status used to update console
protected override void OnRefresh(AsyncStatus status)
{
this.Refresh();
}
///
/// Handles rename standard verb
///
/// name being changed to
/// asynchronous status used to update console
protected override void OnRename(string newText, SyncStatus status)
{
ResultNode resultNode = (ResultNode)this.SelectedNodes[0];
resultNode.DisplayName = newText;
}
///
/// Loads the ListView with data
///
public void Refresh()
{
// Clear existing information
this.ResultNodes.Clear();
// Get some fictitious data to populate the lists with
string[][] users = { new string[] {"Karen", "February 14th"},
new string[] {"Sue", "May 5th"},
new string[] {"Tina", "April 15th"},
new string[] {"Lisa", "March 27th"},
new string[] {"Tom", "December 25th"},
new string[] {"John", "January 1st"},
new string[] {"Harry", "October 31st"},
new string[] {"Bob", "July 4th"}
};
// Populate the list.
foreach (string[] user in users)
{
ResultNode node = new ResultNode();
node.DisplayName = user[0];
node.SubItemDisplayNames.Add(user[1]);
this.ResultNodes.Add(node);
}
}
} // class
} //namespace