在C#中,可以使用ListBox控件的Items
屬性來添加數(shù)據(jù)項(xiàng)。以下是一個(gè)簡單的示例,演示了如何在WinForms應(yīng)用程序中使用ListBox控件添加數(shù)據(jù)項(xiàng):
Items
屬性。例如:public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
// 添加數(shù)據(jù)項(xiàng)到ListBox控件
listBox1.Items.Add("數(shù)據(jù)項(xiàng)1");
listBox1.Items.Add("數(shù)據(jù)項(xiàng)2");
listBox1.Items.Add("數(shù)據(jù)項(xiàng)3");
}
}
在這個(gè)示例中,我們首先使用InitializeComponent()
方法初始化窗體和控件。然后,我們使用Items.Add()
方法向ListBox控件添加三個(gè)數(shù)據(jù)項(xiàng)。
現(xiàn)在,運(yùn)行應(yīng)用程序,你會(huì)看到ListBox控件中顯示了添加的數(shù)據(jù)項(xiàng)。