-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
The logic in Refresh-SiteCombo has two issues:
- If a previously selected site is removed, the line
$state.SiteCombo.Text = $currentValuewill throw an exception because theDropDownStyleisDropDownListand the value is no longer in theItemscollection. - If no site was selected (
$currentValueis empty), after the refresh the first site in the list becomes selected (becauseInitialize-SiteComboBoxsetsSelectedIndex = 0). The expected behavior would be to keep no site selected.
This can be fixed by adjusting the logic to handle these cases correctly.
function Refresh-SiteCombo {
param(
[ValidateSet("Source", "Destination")] [string]$Side
)
$state = $providerUiStates[$Side]
if (-not $state -or $state.CurrentMode -ne "Site") { return }
$currentValue = $state.SiteCombo.Text
if (Initialize-SiteComboBox -Side $Side) {
if ($currentValue) {
$index = $state.SiteCombo.Items.IndexOf($currentValue)
if ($index -ge 0) {
$state.SiteCombo.SelectedIndex = $index
}
# else: The previously selected site is gone. The selection will
# default to index 0 from Initialize-SiteComboBox, which is a reasonable fallback.
}
else {
# No site was selected before, so reset selection.
$state.SiteCombo.SelectedIndex = -1
}
}
}
Originally posted by @gemini-code-assist[bot] in #1 (comment)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels