class Form1 : Form
{
...............................
//btnChange - button
//lstBox - ListBox
private void textBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
TextBox text = sender as TextBox;
lstBox.Items[lstBox.SelectedIndex] = text.Text;
text.Hide();
lstBox.Enabled = true;
this.Controls.Remove(sender as Control);
}
}
private void btnChange_Click(object sender, EventArgs e
{
if (lstBox.SelectedIndex == -1) return;
TextBox text = new TextBox();
text.Location = new Point(
lstBox.Location.X,
lstBox.Location.Y + lstBox.SelectedIndex * lstBox.ItemHeight);
text.Height = lstBox.ItemHeight;
text.Width = lstBox.Width;
text.BorderStyle = BorderStyle.FixedSingle;
text.KeyDown += new KeyEventHandler(textBox_KeyDown);
this.Controls.Add(text);
lstBox.SendToBack();
lstBox.Enabled = false;
text.Focus();
}
}