Hi
developing a video application which is almost complete and just getting rid of a few bugs, one i am stuck on is an auto updating list box
i use filesystemwatcher to update contents of listbox and added a bit of code with a textbox to allow me to change the name of listbox item i click on, this works great apart from when i am editing the filename and the listbox updates at same time as this causes the selected index to change so it crashes my application, i guess i need to hold selecteditem value until i finish editing name but i'm at loss at how to do this
I thought about using a lock but not sure if that would stop the listbox updating as well and i was thinking about a using a Variable to store selected index but cant work out how to do this
using vs2008 c#
private void fileSystemWatcher1_Created(object sender, System.IO.FileSystemEventArgs e)
{
listBox1.Items.Add(e.FullPath);
listBox1.SelectedIndex = listBox1.Items.Count - 1;
listBox1.SelectedIndex = -1;
}
private void listBox1_Click(object sender, EventArgs e)
{
int itemSelected = this.listBox1.SelectedIndex;
string itemText = this.listBox1.Items[itemSelected].ToString();
Rectangle r = this.listBox1.GetItemRectangle(itemSelected);
this.textBox1.Location = new System.Drawing.Point(r.X + 563, r.Y + 569);
this.textBox1.Size = new System.Drawing.Size(r.Width + 4, r.Height - 10);
this.textBox1.Visible = true;
this.textBox1.Text = itemText;
this.textBox1.Focus();
this.textBox1.SelectAll();
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 13)
{
this.listBox1.Items[this.listBox1.SelectedIndex] = this.textBox1.Text;
this.textBox1.Visible = false;
}
if (e.KeyChar == 27)
this.textBox1.Visible = false;