WinForms Edition
Tutorial 3 – AddItem Mode

This tutorial demonstrates how you can manually add information to a list using the AddItem Mode without having to bind C1List to a DataSet.

  1. Create a new .NET project and add:

    • One C1List control (C1List1)
    • Three text boxes (TextBox1, 2, 3)
    • Three labels and three buttons (Button1, 2, 3)

    The form should look like the following:

  2. Set the C1ListBase.DataMode property for the C1List control to AddItem.
  3. In the Form_Load event, add the following code:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    With Me.C1List1        
       .AddItemTitles("First Name; LastName; Phone Number")        
       .AddItem("Greg;Daryll;412-657-3412")        
       .AddItem("Jane;Lambert;567-123-6785")        
       .AddItem("Allen;Clark;675-345-9087")        
       .AddItem("David;Elkins;564-345-2635")        
       .AddItem("Carl;Ziegler;412-678-2351")        
       .AddItem("William;Yahner;412-980-6754")        
    End With
    

    To write code in C#

    C#
    Copy Code
    this.c1List1.AddItemTitles("First Name; LastName; Phone Number");        
    this.c1List1.AddItem("Greg;Daryll;412-657-3412");        
    this.c1List1.AddItem("Jane;Lambert;567-123-6785");        
    this.c1List1.AddItem("Allen;Clark;675-345-9087");      
    this.c1List1.AddItem("David;Elkins;564-345-2635");        
    this.c1List1.AddItem("Carl;Ziegler;412-678-2351");        
    this.c1List1.AddItem("William;Yahner;412-980-6754");
    
  4. Add the following code to the Button1_Click event to allow the user to add a record:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Me.C1List1.AddItem(Me.TextBox1.Text + ";" + Me.TextBox2.Text + ";" + Me.TextBox3.Text)
    

    To write code in C#

    C#
    Copy Code
    this.c1List1.AddItem(this.TextBox1.Text + ";" + this.TextBox2.Text + ";" + this.TextBox3.Text);
    
  5. Add the following code to the Button2_Click event to allow the user to delete a record:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Try        
        Me.C1List1.RemoveItem(Me.C1List1.SelectedIndex)        
    Catch        
        MessageBox.Show("Select an item from the list first.", "List")        
    End Try
    

    To write code in C#

    C#
    Copy Code
    try         
    {        
        this.c1List1.RemoveItem(this.C1List1.SelectedIndex);        
    }         
    catch         
    {        
        MessageBox.Show("Select an item from the list first.", "List");        
    }
    
  6. Add the following to the Button3_Click event to allow the user to clear the list:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Me.C1List1.ClearItems()
    

    To write code in C#

    C#
    Copy Code
    this.c1List1.ClearItems();
    

Run the program and observe the following:

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 C1ListBase.AddItem method for a much faster processing time.

This concludes the tutorial.