internal void SetItemInternal(int index, object value)
{
if (index < 0 || index >= Count)
{
throw new ArgumentOutOfRangeException(nameof(index), index, string.Format(SR.InvalidArgument, nameof(index), index));
}
InnerList[index].Item = value ?? throw new ArgumentNullException(nameof(value));
// If the native control has been created, and the display text of the new list item object
// is different to the current text in the native list item, recreate the native list item...
if (_owner.IsHandleCreated)
{
bool selected = (index == _owner.SelectedIndex);
if (string.Compare(_owner.GetItemText(value), _owner.NativeGetItemText(index), true, CultureInfo.CurrentCulture) != 0)
{
_owner.NativeRemoveAt(index);
_owner.NativeInsert(index, value);
if (selected)
{
_owner.SelectedIndex = index;
_owner.UpdateText();
}
if (_owner.AutoCompleteSource == AutoCompleteSource.ListItems)
{
_owner.SetAutoComplete(false, false);
}
}
else
{
// NEW - FOR COMPATIBILITY REASONS
// Minimum compatibility fix
if (selected)
{
_owner.OnSelectedItemChanged(EventArgs.Empty); //we do this because set_SelectedIndex does this. (for consistency)
_owner.OnSelectedIndexChanged(EventArgs.Empty);
}
}
}
}