I am making myself a project manager and I need to refresh Project List every so often. When I am refreshing the Project Manager, I want to select the item that was previously selected. But that selection causes my text box to unselect, therefore, what happens is that that text box unselects after typing one key.

So outline what happens:

* I try to edit one text box
* Edition causes update in project -> program calls RefreshProjectList()
* RefreshProjectList() on marked position causes selected text box to unselect
* Result: You must select text box after writing one symbol

[*Picture if useful*](http://i.stack.imgur.com/JKok9.jpg)

[*These selected text boxes are struggling to be edited*](http://i.stack.imgur.com/sNEiX.png)

Code:

```
    private void RefreshProjectList() {
        if (BlockListReload)
            return;

        Project selected = (Project)ProjectList.SelectedItem;
        ProjectList.Items.Clear();
        CurrentlyShown.Clear();

        foreach(Project p in Projects){
            if (p.state == State.Planned && ShowPlanned.Checked) {
                CurrentlyShown.Add(p);
                ProjectList.Items.Add(p);
            }
            if (p.state == State.Active && ShowActive.Checked) {
                CurrentlyShown.Add(p);
                ProjectList.Items.Add(p);
            }
            if (p.state == State.Finished && ShowFinished.Checked) {
                CurrentlyShown.Add(p);
                ProjectList.Items.Add(p);
            }
            if (p.state == State.Delayed && ShowDelayed.Checked) {
                CurrentlyShown.Add(p);
                ProjectList.Items.Add(p);
            }
        }

        if (selected == null)
            return;

        if (ProjectList.Items.Contains(selected)) {
            ProjectList.SelectedItem = selected; // IF I REMOVE THIS
        } else {
            if (ProjectList.Items.Count > 0)
                ProjectList.SelectedIndex = 0; // OR THIS LINE, EVERYTHING WORKS
        }
    }

```

If you need more code, I will be happy to provide, but I don't want to spam you with loads of unuseful code.

Q: Why does changing selected item in ListBox cause deselecting of TextBox and how to prevent it?