Exemplo n.º 1
0
        // people say use a DataGridView because they cant hack together a solution.
        // well they were too stupid to hack a elegant soluion like this.
        private void ListView2_DoubleClick(object sender, EventArgs e)
        {
            var textBox = new TextBox
            {
                Bounds  = this.ListView2.SelectedItems[0].Bounds,
                Text    = this.ListView2.SelectedItems[0].Text,
                Visible = true,
            };

            textBox.Enter += (s, s1) =>
            {
                // so the user can replace all the text in the listview item.
                textBox.SelectAll();
            };
            textBox.Leave += (s, e1) =>
            {
                this.ListView2.SelectedItems[0].Text = textBox.Text;

                // do not forget to dispose this control.
                this.ListView2.Controls.Remove(textBox);
                textBox.Dispose();
            };
            textBox.KeyDown += (s, s1) =>
            {
                s1.Handled = true;
                if (s1.KeyData == Keys.Enter)
                {
                    this.ListView2.SelectedItems[0].Text = textBox.Text;

                    // do not forget to dispose this control.
                    this.ListView2.Controls.Remove(textBox);
                    textBox.Dispose();
                }
                else if (s1.KeyData == Keys.Right)
                {
                    // remove selection.
                    textBox.Select(0, 0);
                }
                else if (s1.KeyData == Keys.Left)
                {
                    // remove selection.
                    textBox.Select(0, 0);
                }
            };
            ShareXResources.ApplyDarkThemeToControl(textBox);
            this.ListView2.Controls.Add(textBox);
            this.ActiveControl = textBox;
        }