ComponentOne List for WinForms
In This Topic
    Tutorial 20 - Using the LimitToList Feature
    In This Topic

    In this tutorial, you will learn how to use the LimitToList feature to prevent users from entering an item which does not appear in the combo box list.

    1. Follow steps 1 through 4 of Tutorial 2 - Binding C1Combo to a DataSet to create a project with a C1Combo control bound to a Data Set.
    2. Select the C1Combo control and set its DisplayMember property to First.
    3. Add one button with the text "Limit To List" and one label with the text as it appears in the label below:
    4. Add the following code to the Form_Load event:

      To write code in Visual Basic

      Visual Basic
      Copy Code
      ' The following line is added by Visual Studio 2005.    
      Me.ComposerTableAdapter.Fill(Me.DataSet1.Composer)
      
      ' Add some settings.     
      With Me.C1Combo1    
          .SelectedIndex = 0    
          .DropdownWidth = 500    
          .MaxDropDownItems = 10    
      End With
      

      To write code in C#

      C#
      Copy Code
      // The following line is added by Visual Studio 2005.     
      this.ComposerTableAdapter.Fill(this.DataSet1.Composer);
      
      // Add some settings.     
      this.c1Combo1.SelectedIndex = 0;    
      this.c1Combo1.DropdownWidth = 500;    
      this.c1Combo1.MaxDropDownItems = 10;
      
    5. Add the following code to the Button1_Click event:

      To write code in Visual Basic

      Visual Basic
      Copy Code
      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      
          ' Prevent MisMatch.     
          With Me.C1Combo1    
              .LimitToList = True    
              .AutoCompletion = True    
              .SuperBack = True    
          End With    
      End Sub
      

      To write code in C#

      C#
      Copy Code
      private void Button1_Click( System.object sender, System.EventArgs e)    
      {    
          // Prevent MisMatch.     
          this.c1Combo1.LimitToList = true;   
          this.c1Combo1.AutoCompletion = true;    
          this.c1Combo1.SuperBack = true;    
      }
      

    Run the program and observe the following:

    Click the Limit To List button. You cannot change the text to something that does not appear in the combo box list.

    This concludes the tutorial.