ComponentOne List for WinForms
In This Topic
    Creating a ComboBox with AutoCompletion and KeyDown
    In This Topic

    By manipulating the properties of the C1Combo control, you can customize how users will view and utilize a ComboBox. The AutoCompletion property allows users the option to have text completed for them without entering the entire text. The KeyDown event allows users to press the down arrow key and see the entire contents of the drop down box.

    To enable AutoCompletion and KeyDown

    1. Create a .NET project then add the C1List component to your form.
    2. Add the C1Combo control to your form.
    3. Click the C1Combo smart tag () to open the C1Combo Tasks menu. From the Choose Data Source drop-down box, select Add Project Data Source to open the Data Source Configuration Wizard
    4. In the Data Source Configuration Wizard, select Database and click Next.
    5. Select Dataset and then click Next.
    6. Click the New Connection button to create a new connection or choose one from the drop-down list.
    7. In the Add Connection dialog window, click Browse to specify the location of the data and enter the correct login information. Either select a connection to C1NWind.mdb (on installation located in Documents\ComponentOne Samples\Common) or create a new connection to this database.
    8. Click the Test Connection button to make sure that you have successfully connected to the database or server and click OK. The new string appears on the page.
    9. Click the Next button to continue. A dialog box will appear asking if you would like to add the data file to your project and modify the connection string. Click No.
    10. Save the connection string in the application configuration file by checking the Yes, save the connection as box and entering a name. Click Next to continue.
    11. On the Choose Your Database Objects page, select the tables and fields that you would like in your dataset. For this example expand the Tables node, then expand the Customers node, then place a check next to the LastName box. Click Finish to exit the wizard.

      A DataSet and connection string are added to your project.
    12. Set the AutoCompletion property and the AutoDropDown property to True.
    13. Set the MatchCompare property to PartiallyEqual. This enhances the auto complete feature by specifying a comparison method for input strings.
      Note: For values other than MatchCompareEnum.Equal and MatchCompareEnum.PartiallyEqual, it is advisable to turn off AutoCompletion.
    14. In the Properties window, select the Events button.
    15. Double-click the blank space to the right of the KeyDown event. This will add an event to your code.
    16. Add the following code to the C1Combo1_KeyDown event:

      To write code in Visual Basic

      Visual Basic
      Copy Code
      Me.C1Combo1.DroppedDown = True
      

      To write code in C#

      C#
      Copy Code
      this.C1Combo1.DroppedDown = true;
      

    When you run the application, the AutoCompletion feature is available and, just by pressing the down arrow on the keyboard, the contents of the drop-down menu are visible.