public static void ListViewEditItem(ListView control, int curPos, Control[] editControls, bool edit = false)
        {
            control.Items[curPos].Selected = true;

            control.Items[curPos].EnsureVisible();

            Point startpos = control.Items[curPos].Position;

            List <int> widths = new List <int>();

            int top = control.Top;

            int left = 0 + control.Left;

            foreach (ColumnHeader col in control.Columns)
            {
                widths.Add(col.Width);
            }

            for (int cnt = 0; cnt < editControls.Count(); cnt++)
            {
                editControls[cnt].Text = control.Items[curPos].SubItems[cnt].Text;

                if ((editControls[cnt] is ComboBox) && (control.Items[curPos].SubItems[cnt].Text.Length == 0))
                {
                    ((ComboBox)editControls[cnt]).SelectedIndex = 0;
                }

                editControls[cnt].Top = top + startpos.Y;

                editControls[cnt].Left = left;

                editControls[cnt].Width = widths[cnt];

                SubItemTag tag = new SubItemTag(control, curPos, cnt, edit);

                tag.Controls = editControls;

                editControls[cnt].Tag = tag;

                editControls[cnt].Visible = true;
                editControls[cnt].Enabled = true;
                editControls[cnt].BringToFront();

                left += widths[cnt] + 1;

                if (cnt == 0)
                {
                    editControls[cnt].Select();
                }
            }

            ((SubItemTag)editControls[editControls.Count() - 1].Tag).Controls = editControls;
        }
        public static void ListViewEditFieldKeyPress(Control editControl, Control nextControl, KeyEventArgs e, out bool update)
        {
            update = false;

            SubItemTag tag = (SubItemTag)editControl.Tag;

            if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return) || (e.KeyCode == Keys.Tab))
            {
                e.SuppressKeyPress = true;

                tag.SubItem.Text = editControl.Text;

                if (nextControl != null)
                {
                    nextControl.Select();
                }

                else
                {
                    HideEditControls(editControl);

                    update = true;
                }
            }

            else if ((e.KeyCode == Keys.Cancel) || (e.KeyCode == Keys.Escape))
            {
                if (!tag.IsEdit)
                {
                    tag.List.Items.Remove(tag.Item);
                }

                HideEditControls(editControl);
            }

            else
            {
                if (editControl is TextBox)
                {
                    tag.SubItem.Text = editControl.Text;
                }
            }
        }