In This Topic
There are several ways to add items to the C1ComboBox control:
- To add items to the C1ComboBox control, add the following XAML markup between the <c1:C1ComboBox> and </c1:C1ComboBox> tags:
XAML |
Copy Code
|
<c1:C1ComboBoxItem Height="25" Content="C1ComboBoxItem"/>
<c1:C1ComboBoxItem Height="25" Content="C1ComboBoxItem"/>
<c1:C1ComboBoxItem Height="25" Content="C1ComboBoxItem"/>
<c1:C1ComboBoxItem Height="25" Content="C1ComboBoxItem"/>
|
- Run the program.
- Click the drop-down arrow and observe that four items appear in the drop-down list.
- Add x:Name="C1ComboBox1" to the <c1:C1ComboBox> tag so that the object will have a unique identifier for you to call in code.
- Open the MainPage.xaml.cs or the MainWindow.xaml.cs page.
- Import the following namespace into your project in Code View:
C# |
Copy Code
|
using C1.WPF;
|
Visual Basic |
Copy Code
|
Imports C1.WPF
|
- Add the following code beneath the InitializeComponent() method:
C# |
Copy Code
|
c1ComboBox1.Items.Add(new C1ComboBoxItem() { Content = "C1ComboBoxItem1" });
c1ComboBox1.Items.Add(new C1ComboBoxItem() { Content = "C1ComboBoxItem2" });
c1ComboBox1.Items.Add(new C1ComboBoxItem() { Content = "C1ComboBoxItem3" });
c1ComboBox1.Items.Add(new C1ComboBoxItem() { Content = "C1ComboBoxItem4" });
|
Visual Basic |
Copy Code
|
C1ComboBox1.Items.Add(New C1ComboBoxItem() With {.Content = "C1ComboBoxItem1"})
C1ComboBox1.Items.Add(New C1ComboBoxItem() With {.Content = "C1ComboBoxItem2"})
C1ComboBox1.Items.Add(New C1ComboBoxItem() With {.Content = "C1ComboBoxItem3"})
C1ComboBox1.Items.Add(New C1ComboBoxItem() With {.Content = "C1ComboBoxItem4"})
|
- Run the program.
- Add x:Name="C1ComboBox1" to the <c1:C1ComboBox> tag so that the object will have a unique identifier for you to call in code.
- Open the MainPage.xaml.cs or the MainWindow.xaml.cs page.
- Import the following namespace into your project in Code View:
C# |
Copy Code
|
Using C1.Silverlight;
|
Visual Basic |
Copy Code
|
Imports C1.Silverlight
|
- Add the following code beneath the InitializeComponent() method:
C# |
Copy Code
|
C1ComboBox1.Items.Add(new C1ComboBoxItem() { Content = "C1ComboBoxItem1" });
C1ComboBox1.Items.Add(new C1ComboBoxItem() { Content = "C1ComboBoxItem2" });
C1ComboBox1.Items.Add(new C1ComboBoxItem() { Content = "C1ComboBoxItem3" });
C1ComboBox1.Items.Add(new C1ComboBoxItem() { Content = "C1ComboBoxItem4" });
|
Visual Basic |
Copy Code
|
C1ComboBox1.Items.Add(New C1ComboBoxItem() With {.Content = "C1ComboBoxItem1"})
C1ComboBox1.Items.Add(New C1ComboBoxItem() With {.Content = "C1ComboBoxItem2"})
C1ComboBox1.Items.Add(New C1ComboBoxItem() With {.Content = "C1ComboBoxItem3"})
C1ComboBox1.Items.Add(New C1ComboBoxItem() With {.Content = "C1ComboBoxItem4"})
|
- Run the program.
Complete the following steps:
- Add x:Name="C1ComboBox1" to the <c1:C1ComboBox> tag so that the object will have a unique identifier for you to call in code.
- Open the MainWindow.Xaml.cs page or the MainPage.xaml.cs page (or the .vb page if using Visual Basic).
- Import the following namespace into the project:
Visual Basic |
Copy Code
|
Imports System.Collections.Generic
|
C# |
Copy Code
|
using System.Collections.Generic;
|
- Create your list by adding the following code beneath the InitializeComponent() method:
Visual Basic |
Copy Code
|
Dim dropDownList As New List(Of String)()
dropDownList.Add("C1ComboBoxItem1")
dropDownList.Add("C1ComboBoxItem2")
dropDownList.Add("C1ComboBoxItem3")
dropDownList.Add("C1ComboBoxItem4")
|
C# |
Copy Code
|
List<string> dropDownList = new List<string>();
dropDownList.Add("C1ComboBoxItem1");
dropDownList.Add("C1ComboBoxItem2");
dropDownList.Add("C1ComboBoxItem3");
dropDownList.Add("C1ComboBoxItem4");
|
- Add the list to the combo box by setting the ItemsSource property:
Visual Basic |
Copy Code
|
C1ComboBox1.ItemsSource = dropDownList
|
C# |
Copy Code
|
c1ComboBox1.ItemsSource = dropDownList;
|
- Run the program.
Complete the following steps:
- In the Properties window, click the Items ellipsis button
to open the Collection Editor: Items dialog box.
Collection Editor: Items
- Click Add to add a C1ComboBoxItem to the C1ComboBox control.