/// <summary>
        /// Displays a dialog to edit a complex value.
        /// </summary>
        private void EditComplexValue(ComplexValue complexValue)
        {
            object value = null;

            if (!complexValue.Value.GetType().IsArray)
            {
                value = new EditValueDlg().ShowDialog(complexValue.Value, true);
            }
            else if (complexValue.Value.GetType() == typeof(byte[]))
            {
                value = new EditBinaryDlg().ShowDialog((byte[])complexValue.Value);
            }
            else
            {
                if (complexValue.Value.GetType() != typeof(ComplexValue[]))
                {
                    value = new EditArrayDlg().ShowDialog(complexValue.Value, m_readOnly);
                }
            }

            if (value != null)
            {
                // update the complex value.
                complexValue.Value = value;

                // serialize the entire complex value starting with the root object.
                m_rawValue = m_binaryValue.Parse(m_complexValue);

                // update the diplay.
                UpdateView();
            }
        }
        /// <summary>
        /// Shows the edit array dialog for an element.
        /// </summary>
        private void ViewMI_Click(object sender, System.EventArgs e)
        {
            if (ArrayLV.SelectedItems.Count == 1)
            {
                ListViewItem item = ArrayLV.SelectedItems[0];

                if (item.Tag == null || !item.Tag.GetType().IsArray)
                {
                    return;
                }

                try
                {
                    int index = ArrayLV.SelectedIndices[0];

                    // get andOpc.Convert the new value.
                    object value = new EditArrayDlg().ShowDialog(item.Tag, m_readOnly);

                    if (m_readOnly || value == null)
                    {
                        return;
                    }

                    // update the array.
                    ((System.Array)m_value).SetValue(value, index);

                    // update the list view.
                    ArrayLV.Items[index].Tag = value;
                    ArrayLV.Items[index].SubItems[1].Text = Opc.Convert.ToString(value);

                    // clear index.
                    m_index = -1;
                    ArrayLV.SelectedItems.Clear();
                    item.Selected = true;
                }
                catch (System.Exception exception)
                {
                    MessageBox.Show(exception.Message);
                }
            }
        }
        /// <summary>
        /// Called when the edit array button is clicked.
        /// </summary>
        private void EditBTN_Click(object sender, System.EventArgs e)
        {
            try
            {
                object value = null;

                ComplexItem complexItem = ComplexTypeCache.GetComplexItem(m_itemID);

                if (complexItem != null)
                {
                    value = new EditComplexValueDlg().ShowDialog(complexItem, m_value, m_readOnly, true);
                }

                else if (m_value.GetType().IsArray)
                {
                    value = new EditArrayDlg().ShowDialog(m_value, m_readOnly);
                }

                if (m_readOnly || value == null)
                {
                    return;
                }

                // update the array.
                Set(value, m_readOnly);

                // send change notification.
                if (ValueChanged != null)
                {
                    ValueChanged(this, m_value);
                }
            }
            catch (System.Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }