/// <summary>
        /// Edits the item template.
        /// </summary>
        private void EditTemplate(OpcDa::Item template)
        {
            // prompt user to edit the template.
            OpcDa::Item[] templates = new ItemListEditDlg().ShowDialog(new OpcDa::Item[] { template }, IsReadItem, false);
            if (templates == null || templates.Length != 1)
            {
                return;
            }
            // get existing items without applying defaults.
            ArrayList items = new ArrayList();

            foreach (ListViewItem item in ItemListLV.Items)
            {
                if (item.Tag != null && item.Tag.GetType() == typeof(OpcDa::Item))
                {
                    if (item.Tag != m_template)
                    {
                        items.Add(item.Tag);
                    }
                }
            }

            // re-initialize the list with the new template.
            Initialize(templates[0]);

            // add items back.
            foreach (OpcDa::Item item in items)
            {
                AddItem(item);
            }
        }
        /// <summary>
        /// Edits a group of items.
        /// </summary>
        private void EditMI_Click(object sender, System.EventArgs e)
        {
            // check if the template if being editied.
            if (ItemListLV.SelectedItems.Count == 1)
            {
                if (ItemListLV.SelectedItems[0].Tag == m_template)
                {
                    EditTemplate(m_template);
                    return;
                }
            }

            // build list of items to edit (exclude template).
            ArrayList itemList = new ArrayList(ItemListLV.SelectedItems.Count);

            foreach (ListViewItem item in ItemListLV.SelectedItems)
            {
                if (item.Tag != null && item.Tag.GetType() == typeof(OpcDa::Item))
                {
                    if (item.Tag != m_template)
                    {
                        itemList.Add(item.Tag);
                    }
                }
            }

            // prompt user to edit list of items.
            OpcDa::Item[] items = new ItemListEditDlg().ShowDialog((OpcDa::Item[])itemList.ToArray(typeof(OpcDa::Item)), IsReadItem, false);

            if (items == null)
            {
                return;
            }

            // remove changed items.
            RemoveMI_Click(sender, e);

            // add changed items.
            foreach (OpcDa::Item item in items)
            {
                AddItem(item);
            }
        }
        /// <summary>
        /// Creates a new item.
        /// </summary>
        private void NewMI_Click(object sender, System.EventArgs e)
        {
            OpcDa::Item template = null;

            // copy the current selection.
            if (ItemListLV.SelectedItems.Count > 0)
            {
                template = (OpcDa::Item)((OpcDa::Item)ItemListLV.SelectedItems[0].Tag).Clone();
            }

            // prompt user to edit new item.
            OpcDa::Item[] items = new ItemListEditDlg().ShowDialog(new OpcDa::Item[] { template }, IsReadItem, true);

            if (items == null)
            {
                return;
            }

            // add new items.
            foreach (OpcDa::Item item in items)
            {
                AddItem(item);
            }
        }