TX Text Control Source Code Library

Displaying a ComboBox to change the field's text value

In another sample, we showed how to inherit from the TextField class to add new functionality to these fields. The same approach is used in this sample that illustrates how to display a ComboBox with possible options from which the user can choose.

Consider an application in which users should complete form fields. A ComboBox that displays all possible values is much easier for the user to select and much easier for the developer to validate.

The technique to inherit from the TextField base class is the same as in the above mentioned sample, so in this sample, we are only going to look at the specifics.

The class DropDownField consists of a new member: ListItems. This string array contains the strings that are displayed in the ComboBox, when the user double-clicks on a specific field. Every field should have a unique name to identify these 'special fields'. In the constructor, the parent TextControl object and the string array is passed:

public DropDownField(TextControl TextControl, string[] ListItems)

On creating the new field, some events are attached to the parent TextControl object. On double-clicking the field, a ComboBox that has been added to the TextControl's Controls collection in the constructor's logic is displayed.

The ComboBox should be displayed exactly under the field. The position can be retrieved using the InputPosition class of TextControl. After selecting a specific value from the ComboBox, the text of the specific field is replaced and the ComboBox can be hidden again.

The sample requires Visual Studio 2003 and at least a trial version of TX Text Control .NET for Windows Forms 13.0.

 
 

Products

Support

Downloads

Corporate

Buy Now