views:

372

answers:

1

I am using owner draw variable style for a listbox( winforms 2.0) when a user selects an items I want to draw an edit control in that cell Is that doable not a drop down but an actual edit control appearing in the cell or item as it were how thanks

+1  A: 

I'm using some similar for ListView. Method is:

  1. Create TextBox, add to Controls array, and hide one.

    innerTextBox.Size = new Size(0, 0);

    innerTextBox.Location = new Point(0, 0);

    this.Controls.AddRange(new Control[] { this.innerTextBox });

    innerTextBox.KeyPress += new KeyPressEventHandler(this.EditOver);

    innerTextBox.LostFocus += new EventHandler(this.FocusOver);

    innerTextBox.Hide();

    innerTextBox.Text = "";

  2. On DoubleClick event bind own method where find selected Item and get value to TextBox

    this.DoubleClick += new EventHandler(this.EditableDoubleClick);

    private void EditableDoubleClick(object sender, System.EventArgs e) {

    selectedItemText = selectedItem.ToString();

    innerTextBox.Size = new Size(subItemRect.right - subItemRect.left, subItemRect.bottom - subItemRect.top);

    innerTextBox.Location = new Point(subItemRect.left, subItemRect.top);

    innerTextBox.Show();

    innerTextBox.Text = selectedItemText;

    }

  3. On lost focus in TextBox - set value back into selected item.

    selectedItem = innerTextBox.Text;

Chernikov