void ReloadDatabaseList(bool keepSameDatabase, bool setFocus = true) { string databaseName = string.Empty; try { var sel = SelectedServer; if (keepSameDatabase) { databaseName = SelectedDatabase; } if (sel != null) { cbDatabase.ItemsSource = ItemFactory.BuildDatabase(StudioController.ListDatabase(sel)); _databaseChangedByUser = false; // changed server - try to restore database user worked with last time if (string.IsNullOrEmpty(databaseName)) { databaseName = _userPref.GetByName(UserPref_ServerDatabase + sel.ServerName); } var previousDatabaseWasFound = false; if ((databaseName != null) && (cbDatabase.Items != null)) { foreach (Item item in cbDatabase.ItemsSource) { if (item.Name == databaseName) { cbDatabase.SelectedValue = item; previousDatabaseWasFound = true; break; } } } // select the first database if a database previously chosen by user does not exist on a server any more if (!previousDatabaseWasFound && (cbDatabase.Items != null) && (cbDatabase.Items.Count > 0)) { cbDatabase.SelectedIndex = 0; } _databaseChangedByUser = true; _userPref.StoreByName(UserPref_LastSelectedServer, sel.ServerName); _userPref.Save(); if (previousDatabaseWasFound) { // we managed to find our database - restore search text RestoreLastSearchTextFromUserProfile(); if (setFocus) { txtSearch.Focus(); } } else { ClearSearchText(); if (setFocus) { cbDatabase.Focus(); } } } else { ClearSearchText(); } } catch (Exception ex) { log.Error("Server Selection:" + ex.Message, ex); } }