Skip to content

Commit 795ebca

Browse files
committed
Add explicit handling for popup list get selection fail
1 parent 4c086fd commit 795ebca

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

Source/ExcelDna.IntelliSense/UIMonitor/PopupListWatcher.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,22 @@ void UpdateSelectedItem()
155155
ListBounds = Win32Helper.GetWindowBounds(_hwndPopupList);
156156

157157
_selectedItemIndex = Win32Helper.GetListViewSelectedItemInfo(hwndListView, out text, out itemBounds);
158-
itemBounds.Offset(ListBounds.Left, ListBounds.Top);
159-
SelectedItemBounds = itemBounds;
160-
SelectedItemText = text;
158+
if (string.IsNullOrEmpty(text))
159+
{
160+
// We (unexpectedly) failed to get information about the selected item
161+
Logger.WindowWatcher.Warn($"PopupList UpdateSelectedItem - IsVisible but GetListViewSelectedItemInfo failed ");
162+
_selectedItemIndex = -1;
163+
SelectedItemText = string.Empty;
164+
SelectedItemBounds = Rect.Empty;
165+
ListBounds = Rect.Empty;
166+
}
167+
else
168+
{
169+
// Normal case - all is OK
170+
itemBounds.Offset(ListBounds.Left, ListBounds.Top);
171+
SelectedItemBounds = itemBounds;
172+
SelectedItemText = text;
173+
}
161174
}
162175
OnSelectedItemChanged();
163176
}

0 commit comments

Comments
 (0)