我們要實現上圖中的效果,需要如下的操作:
打開集合編輯器,並點擊“添加”,如圖1
Text和Value中都輸入需要在列表中顯示的選項,如圖2
在Items中添加數據,如圖3
圖1 圖2 圖3設置默認選項,需要在代碼中實現
VB: Private Sub Button1_Click(senderAs Object, e As EventArgs)Handles Button1.Click Me.PopList1.Show() If Label8.Text.Trim().Length <= 0 Then Me.PopList1.SetSelections(Me.PopList1.Groups(0).Items(6)) End If End Sub
C#: private void Button1_Click(object sender, EventArgs e) { PopList1.Show(); If (Label8.Text.Trim().Length <= 0) { PopList1.SetSelections(PopList1.Groups[0].Items[0]); } }
默認設置不允許多選
在內容選擇完成後的事件
事件代碼:
VB: Private Sub PopList1_Selected(senderAs Object, e As EventArgs)Handles PopList1.Selected Me.Label8.Text = PopList1.Selection.Text End Sub
C#: private void PopList1_Selected(object sender, EventArgs e) { this.Label8.Text = PopList1.Selection.Text; }