When in AddItem mode, List for WinForms allows you to populate a list or combo box control (C1List or C1Combo) manually by using the AddItem, RemoveItem, InsertItem and ClearItems methods. In this mode, your application determines what data is contained within the list control.
To use AddItem mode, set the DataMode property of the control to AddItem at design-time, then use the AddItem method to populate the control.
The AddItem method allows you to populate individual rows within the list. The following code adds the names and street addresses to the list control:
To write code in Visual Basic
| Visual Basic |
Copy Code
|
|---|---|
Me.C1List1.AddItem "Smith;John;210 Elm St." Me.C1List1.AddItem "Doe;Jane;100 Oak St." |
|
To write code in C#
| C# |
Copy Code
|
|---|---|
this.c1List1.AddItem("Smith;John;210 Elm St.");
this.c1List1.AddItem("Doe;Jane;100 Oak St.");
|
|
![]() |
Note: The default AddItem separator is ";".You can choose a custom separator by setting the AddItemSeparator property at design-time or from code. |
The RemoveItem method allows you to remove rows from the list. The code below allows you to remove the selected row from the list control:
To write code in Visual Basic
| Visual Basic |
Copy Code
|
|---|---|
Me.C1List1.RemoveItem(Me.C1List1.SelectedIndex) |
|
To write code in C#
| C# |
Copy Code
|
|---|---|
this.c1List1.RemoveItem(this.c1List1.SelectedIndex); |
|
The ClearItems method removes all items from the list population. The code below removes the entire population from the list control:
To write code in Visual Basic
| Visual Basic |
Copy Code
|
|---|---|
Me.C1List1.ClearItems() |
|
To write code in C#
| C# |
Copy Code
|
|---|---|
this.c1List1.ClearItems(); |
|
The InsertItem method will insert an item to a specified position. The code below will insert a second row:
To write code in Visual Basic
| Visual Basic |
Copy Code
|
|---|---|
Me.C1List1.InsertItem("Carl;Ziegler;51 Pine St.", 1)
|
|
To write code in C#
| C# |
Copy Code
|
|---|---|
this.c1List1.InsertItem("Carl;Ziegler;51 Pine St.", 1);
|
|