ComponentOne List for WinForms
In This Topic
    Tutorial 21 – Design-Time Support for C1Combo's AddItem Mode
    In This Topic

    Design-time support for the AddItem mode of C1List is now available. The following steps demonstrate how to add items and set a layout at design time.

    1. Create a new project.
    2. Double-click the C1Combo icon in Visual Studio's Toolbox to add it to the Form. 
      Note: See Adding the C1List Components to a Project for information on adding a component to the Toolbox.
    3. Select the DataMode property in the Properties window and change it to AddItem.
    4. Open the C1List Designer by clicking the ellipsis button next to the Columns property in the Properties window.
    5. Add a column by clicking the Insert button in the C1List Designer, and change its Caption property to Name.
    6. Add another column and change its Caption property to Contacted.
    7. Expand the Contacted column's ValueItems property by clicking the ValueItems node, and set the Translate property to True.
    8. With ValueItems still expanded, click the ellipsis button next to the Values property, and the ValueItem Collection Editor appears.
    9. Click the Add button and the first ValueItem member appears in the left pane. In the right pane enter No in the DisplayValue box and enter 0 in the Value box.
    10. Add another ValueItem member. Enter Yes in the DisplayValue box and enter 1 in the Value box.
    11. Open the Split Collection Editor by clicking the ellipsis button next to the Splits property in the Properties window.
    12. In the right pane, click the ellipsis button next to the DisplayColumns property. The DisplayColumns Collection Editor appears.
    13. Select the Name column: set its Visible property to True and its Width to 200.
    14. Select the Contacted column and set its Visible property to True.
    15. Click OK to close the editor windows.
    16. Add the following code to the Form_Load event:

      To write code in Visual Basic

      Visual Basic
      Copy Code
      With Me.C1Combo1    
          .HoldFields()    
          .AddItem("Greg Daryll;0")    
          .AddItem("Jane Lambert;1")    
          .AddItem("Allen Clark;1")    
          .AddItem("David Elkins;1")    
          .AddItem("Carl Ziegler;0")    
          .AddItem("William Yahner;1")    
      End With
      

      To write code in C#

      C#
      Copy Code
      this.c1Combo1.HoldFields();    
      this.c1Combo1.AddItem("Greg Daryll;0");    
      this.c1Combo1.AddItem("Jane Lambert;1");    
      this.c1Combo1.AddItem("Allen Clark;1");    
      this.c1Combo1.AddItem("David Elkins;1");    
      this.c1Combo1.AddItem("Carl Ziegler;0");    
      this.c1Combo1.AddItem("William Yahner;1");
      

    Run the program and observe the following:

    Note: For faster data processing, use the AddItem method.

    For example, replace the code entered in the Form_Load event with the following code:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    With Me.C1Combo1    
        .HoldFields()    
        .SuspendBinding()    
        .AddItem ("Greg Daryll;0")    
        .AddItem ("Jane Lambert;1")    
        .AddItem ("Allen Clark;1")    
        .AddItem ("David Elkins;1")    
        .AddItem ("Carl Ziegler;0")    
        .AddItem ("William Yahner;1")    
        .ResumeBinding()    
        .Rebind()    
    End With
    

    To write code in C#

    C#
    Copy Code
    this.c1Combo1.HoldFields();    
    this.c1Combo1.SuspendBinding();    
    this.c1Combo1.AddItem ("Greg Daryll;0");    
    this.c1Combo1.AddItem ("Jane Lambert;1");    
    this.c1Combo1.AddItem ("Allen Clark;1");    
    this.c1Combo1.AddItem ("David Elkins;1");    
    this.c1Combo1.AddItem ("Carl Ziegler;0");    
    this.c1Combo1.AddItem ("William Yahner;1");    
    this.c1Combo1.ResumeBinding();    
    this.c1Combo1.Rebind();
    

    In this tutorial only a small amount of data was used, so you may not notice a difference in the processing time. For larger amounts of data, use the AddItem method for a much faster processing time.

    This concludes the tutorial.