To create a edittable list box take a list box and enter items in it.now select the list box double click event from event list.
private void listBox1_DoubleClick(object sender, EventArgs e)
{
//get list item index
int itemno = this.listBox1.SelectedIndex;
//get list item tex;
string itemvalue = this.listBox1.Items[itemno].ToString();
Rectangle rect = this.listBox1.GetItemRectangle(itemno);
this.textBox1.BackColor = Color.Aqua;
this.textBox1.BorderStyle = BorderStyle.Fixed3D;
//get list item drawing point
this.textBox1.Location = new System.Drawing.Point(rect.X + 12, rect.Y + 12);
this.textBox1.Size = new System.Drawing.Size(rect.Width + 5, rect.Height - 5);
this.textBox1.Visible = true;
this.textBox1.Text = itemvalue;
this.textBox1.Focus();
this.textBox1.SelectAll();
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
//if User Press Enter button
if (e.KeyChar == 13)
{
this.listBox1.Items[this.listBox1.SelectedIndex] = this.textBox1.Text;
this.textBox1.Visible = false;
}
//If User press Escape button
if (e.KeyChar == 27)
{
this.textBox1.Visible = false;
}
}
|
No comments:
Post a Comment