The AutoAppend class provides choice-list auto-append capabilities for editable combo boxes, etc.
public class AutoAppend : IDisposable
Often editable combo boxes in your applications can benefit from reusing previously user supplied entries in their choice-list, as in IE's address bar combo box and in the "Find" combo box in VS.NET.
The AutoAppend class will easily enable this functionality in an associated combo box. In fact, this class is more abstract in that it can take any control and an IList reference and enable "AutoAppend" logic on them as described below.
Associate your control with this class through the AutoAppendInfo structure. The AutoAppendInfo structure will let you associate a control with an IList reference and a Category string to an AutoAppend instance.
Once you set up this association, the AutoAppend instance listens to the Validated event thrown by the control and inserts the new entry on top of the supplied IList or if already in the list, moves the entry to top of the list. When the control gets disposed, it persists these entries in the registry in a key based on the corresponding Category string. The next time the control is created and associated, the AutoAppend instance will pick up the persisted information corresponding to the Category and apply that information to the IList instance.
Persistance is done in the registry under the HKLU key making the entries specific to the user and global to the machine (usable across applications). Due to the previous behavior, the very first instantiation of the above control will set the control's text and the IList to be empty.
You can make any number of associations with one AutoAppend instance.
This is how you would associate a combo box with an instance of the AutoAppend class:
this.autoAppend = new AutoAppend(); this.autoAppend.SetAutoAppend(this.comboBox1, new AutoAppendInfo(true, "HttpAddress", this.comboBox1.Items, 30)); // To disassociate call this: this.autoAppend.SetAutoAppend(this.comboBox1, new AutoAppendInfo(false, String.Empty, null, 30));
Creates a new instance of the AutoAppend class.
Releases all setup associations.
public void Dispose()
This will also persist the exisiting information before releasing the associations.
Override this to release the unmanaged resources used by the control and optionally releases the managed resources.
protected virtual void Dispose(bool disposing)
True to release both managed and unmanaged resources; False to release only unmanaged resources.
This member overrides Object.Finalize.
protected void Finalize()
Returns the AutoAppendInfo associated with a control.
public virtual AutoAppendInfo GetAutoAppend(Control control)
The control whose AutoAppend info is required.
The corresponding AutoAppendInfo value. If this control is not associated yet, then an AutoAppendInfo with its AutoAppend value set to False will be returned.
Forces an entry into the control's AutoAppend list.
public void InsertOrMoveToTop(Control control, string item)
The control whose AutoAppend list is to be updated.
The value that is to be appended to the list.
The AutoAppend instance automatically inserts entries into the list when the user enters a new value and leaves the control (when Validated will be fired). However, you might want new entries to be added when, for example, the user hits the Enter key. You do so by calling this method with the new value which will insert the new value into the list.
Associates a control with this instance by providing its AutoAppendInfo.
public virtual void SetAutoAppend(Control control, AutoAppendInfo autoAppendInfo)
The control in which to AutoAppend.
Calling this will enable AutoAppend behavior in the control. Take a look at the AutoAppend class reference for detailed information on this behavior.To disassociate a control from the AutoAppend instance, call this method with the AutoAppendInfo's AutoAppend value set to False.