/// <summary>
 /// Performs custom actions before a cell is validated</summary>
 /// <param name="sender">Sender control</param>
 /// <param name="e">Event args</param>
 void listView_CellValidating(object sender, DataBoundListView.ListViewCellValidatingEventArgs e)
 {
     string propertyName = m_listView.ItemProperties[e.ColumnIndex].Name;
     var target = m_targets[e.RowIndex];
     if (target is IPropertyValueValidator)
     {
         string errorMessage;
         e.Cancel =
             !((IPropertyValueValidator) target).Validate(propertyName, e.FormattedValue, out errorMessage);
         if (e.Cancel)
             Outputs.WriteLine(OutputMessageType.Warning, errorMessage);
     }
 }
        /// <summary>
        /// Sets up targets view Control</summary>
        /// <returns>Control for viewing targets</returns>
        protected Control SetUpTargetsView()
        {
            m_userControl = new UserControl { Margin = new Padding(3) };
            //panel.BackColor = Color.DeepSkyBlue;
            m_userControl.Dock = DockStyle.Fill;
           
            m_userControl.AutoSize = true;

            m_addTargetButton = new SplitButton();
            m_addTargetButton.Text = AddString.Localize();
            m_addTargetButton.Location = new Point(m_userControl.Margin.Left,
                m_userControl.Height - m_userControl.Margin.Bottom - m_addTargetButton.Height - m_addTargetButton.Margin.Size.Height);

            m_addTargetButton.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
            m_addTargetButton.AutoSizeMode = AutoSizeMode.GrowAndShrink;
  
            m_listView = new DataBoundListView();          
            m_listView.DataSource = m_targets;
            m_listView.BindingContext = m_userControl.BindingContext;
            m_listView.AlternatingRowColors = true;
            m_listView.MultiSelect = false;
            m_listView.CheckBoxes = true;
            
            //m_listView.BackColor = SystemColors.MenuHighlight;
            m_listView.Location = new Point(m_userControl.Margin.Left, m_userControl.Margin.Top);
            m_listView.Size = new Size(m_userControl.Width - m_userControl.Margin.Left - m_userControl.Margin.Right,
                m_userControl.Height - m_userControl.Margin.Top - m_userControl.Margin.Bottom - 
                m_addTargetButton.Height - m_addTargetButton.Margin.Top - m_addTargetButton.Margin.Size.Height);
            m_listView.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Right;
            m_listView.Name = "targetsListView";
            m_listView.CellValidating += listView_CellValidating;
            m_listView.ItemChecked += listView_ItemChecked;
            m_listView.ItemCheck += new ItemCheckEventHandler(listView_ItemCheck);
            m_listView.MouseUp += new MouseEventHandler(listView_MouseUp);
         
            m_userControl.Controls.Add(m_listView);
            m_userControl.Controls.Add(m_addTargetButton);

            if (ShowAsDialog)
            {
                m_okButton = new System.Windows.Forms.Button();
                m_okButton.Name = "m_okButton";
                m_okButton.Text = "OK";
                m_okButton.DialogResult = System.Windows.Forms.DialogResult.OK;
                m_okButton.Location = new Point(m_userControl.Width - m_userControl.Margin.Right - m_okButton.Width,
                    m_userControl.Height - m_userControl.Margin.Bottom - m_okButton.Height - m_okButton.Margin.Size.Height);
                m_okButton.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
                m_userControl.Controls.Add(m_okButton);
            }

        
            m_addTargetButton.ShowSplit = true;
            m_addTargetButton.ContextMenuStrip = new ContextMenuStrip();
            foreach (var targetProvider in TargetProviders)
            {
                if (targetProvider.CanCreateNew)
                    m_addTargetButton.ContextMenuStrip.Items.Add(AddNewString + targetProvider.Name);
            }
            m_addTargetButton.ContextMenuStrip.ItemClicked += new ToolStripItemClickedEventHandler(ContextMenuStrip_ItemClicked);
            if (m_addTargetButton.ContextMenuStrip.Items.Count ==1)
            {
                m_addTargetButton.ShowSplit = false;
                ToolStripItem onlyItem = m_addTargetButton.ContextMenuStrip.Items[0];
                m_addTargetButton.Text = onlyItem.Text;
                m_addTargetButton.Click += delegate
                                               {
                                                   foreach (var targetProvider in TargetProviders)
                                                   {
                                                       if (AddNewString + targetProvider.Name == m_addTargetButton.Text)
                                                       {
                                                           targetProvider.AddTarget(targetProvider.CreateNew());
                                                           break;
                                                       }
                                                   }
                                               };
            }

            m_userControl.Name = "Targets".Localize();

              return m_userControl;
        }