< Summary - PropertyGridHelpers Code Coverage

Information
Class: PropertyGridHelpers.Controls.AutoCompleteComboBox
Assembly: PropertyGridHelpers
File(s): c:\agent\_work\9\s\Code\PropertyGridHelpers\Controls\AutoCompleteComboBox.cs
Tag: PropertyGridHelpers Build_2025.7.15.1_#485
Line coverage
100%
Covered lines: 37
Uncovered lines: 0
Coverable lines: 37
Total lines: 136
Line coverage: 100%
Branch coverage
100%
Covered branches: 10
Total branches: 10
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBlocks covered Blocks not covered Branch coverage Crap Score Cyclomatic complexity Line coverage
AutoCompleteComboBox()80----
.ctor()--100%11100%
get_Value()--100%22100%
set_Value(...)--100%88100%
get_Context()--100%11100%
set_Context(...)--100%11100%
get_Culture()--100%11100%
set_Culture(...)--100%11100%
OnSelectedValueChanged(...)30100%11100%
OnSelectedValueChanged(...)30----
OnLeave(...)30100%11100%
OnLeave(...)30----

File(s)

c:\agent\_work\9\s\Code\PropertyGridHelpers\Controls\AutoCompleteComboBox.cs

#LineLine coverage
 1using PropertyGridHelpers.Support;
 2using PropertyGridHelpers.UIEditors;
 3using System;
 4using System.ComponentModel;
 5using System.Drawing.Design;
 6using System.Globalization;
 7using System.Windows.Forms;
 8
 9namespace PropertyGridHelpers.Controls
 10{
 11    /// <summary>
 12    /// A specialized <see cref="ComboBox"/> designed for use in a <see cref="PropertyGrid"/>
 13    /// drop-down editor, supporting auto-completion and value commitment handling.
 14    /// </summary>
 15    /// <remarks>
 16    /// This control is intended for use in property editors where a user-friendly
 17    /// auto-complete experience is desired, such as file paths, URLs, or custom lists.
 18    /// The control implements <see cref="IDropDownEditorControl"/>, allowing it to be hosted
 19    /// by a <see cref="UITypeEditor"/> like <see cref="UIEditors.DropDownVisualizer{TControl}"/>.
 20    /// </remarks>
 21    /// <seealso cref="ComboBox"/>
 22    /// <seealso cref="IDropDownEditorControl"/>
 23    public class AutoCompleteComboBox
 24        : ComboBox, IDropDownEditorControl
 25    {
 26        /// <summary>
 27        /// Initializes a new instance of the <see cref="AutoCompleteComboBox"/> class.
 28        /// </summary>
 29        /// <remarks>
 30        /// Default settings:
 31        /// <list type="bullet">
 32        /// <item><description><see cref="ComboBox.DropDownStyle"/> = <see cref="ComboBoxStyle.DropDown"/></description>
 33        /// <item><description><see cref="ComboBox.AutoCompleteMode"/> = <see cref="AutoCompleteMode.SuggestAppend"/></d
 34        /// <item><description><see cref="ComboBox.AutoCompleteSource"/> = <see cref="AutoCompleteSource.CustomSource"/>
 35        /// </list>
 36        /// </remarks>
 8837        public AutoCompleteComboBox()
 8038        {
 8839            DropDownStyle = ComboBoxStyle.DropDown;
 8840            AutoCompleteMode = AutoCompleteMode.SuggestAppend;
 8841            AutoCompleteSource = AutoCompleteSource.CustomSource;
 8842        }
 43
 44        /// <summary>
 45        /// Gets or sets the value displayed and edited in the combo box.
 46        /// </summary>
 47        /// <value>
 48        /// The current text of the combo box.
 49        /// </value>
 50        /// <remarks>
 51        /// This property is used by <see cref="DropDownVisualizer{TControl}"/> to transfer
 52        /// data between the editor and the hosting environment.
 53        /// </remarks>
 54        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
 55        public object Value
 56        {
 57            get
 3258            {
 4059                if (SelectedItem is ItemWrapper<object> wrapper)
 2460                    return wrapper.Value;
 3261                return Text; // fallback
 3262            }
 63            set
 3264            {
 4065                if (value != null)
 2866                {
 67                    // Try to find the matching item wrapper
 13268                    foreach (var item in Items)
 4069                    {
 4870                        if (item is ItemWrapper<object> wrapper && Equals(wrapper.Value, value))
 1671                        {
 2472                            SelectedItem = wrapper;
 2473                            return;
 74                        }
 3275                    }
 76
 77                    // Fallback to setting raw text
 2878                    Text = value.ToString();
 2079                }
 4080            }
 81        }
 82
 83        /// <summary>
 84        /// Gets or sets the type descriptor context in which the control is being used.
 85        /// </summary>
 86        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
 87        public ITypeDescriptorContext Context
 88        {
 489            get;
 2090            set;
 91        }
 92
 93        /// <summary>
 94        /// Gets or sets the culture to use for localization or formatting.
 95        /// </summary>
 96        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
 97        public CultureInfo Culture
 98        {
 499            get;
 20100            set;
 101        }
 102
 103        /// <summary>
 104        /// Occurs when the user finishes editing and the value should be committed.
 105        /// </summary>
 106        /// <remarks>
 107        /// This event is used to close the drop-down when editing is complete.
 108        /// It is raised when either:
 109        /// <list type="bullet">
 110        /// <item><description>The selected value changes</description></item>
 111        /// <item><description>The control loses focus</description></item>
 112        /// </list>
 113        /// </remarks>
 136114        public event EventHandler ValueCommitted = delegate { };
 115
 116        /// <summary>
 117        /// Raises the <see cref="ListControl.SelectedValueChanged"/> event and notifies that editing is complete.
 118        /// </summary>
 119        /// <param name="e">Event data.</param>
 120        protected override void OnSelectedValueChanged(EventArgs e)
 28121        {
 36122            base.OnSelectedValueChanged(e);
 36123            ValueCommitted.Invoke(this, EventArgs.Empty);
 36124        }
 125
 126        /// <summary>
 127        /// Raises the <see cref="Control.Leave"/> event and notifies that editing is complete.
 128        /// </summary>
 129        /// <param name="e">Event data.</param>
 130        protected override void OnLeave(EventArgs e)
 12131        {
 20132            base.OnLeave(e);
 20133            ValueCommitted.Invoke(this, EventArgs.Empty);
 20134        }
 135    }
 136}