1

我在这里要做的是,对于添加到 中的每个新项目ComboBox,标签的文本属性将显示前一个数字的 +1。

假设我没有为项目分配编号,我该如何写出来。

Items              Label
Tom                 1
Jane                2
Mary                3
John                4
etc..               etc..

编辑:我ComboBox的绑定到数据源。

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click

    Dim studentcheck = StudentTableAdapter.checkstudent(StudentNameTextBox.Text, StudentAddressTextBox.Text)

    If StudentNameTextBox.Text.Length = 0 Then

        MsgBox("Name is Empty")

    ElseIf StudentAddressTextBox.Text.Length = 0 Then

        MsgBox("Address is empty")

    ElseIf studentcheck Is Nothing Then

        Me.Validate()
        Me.StudentBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.LibraryDataSet)
        frmAddLoan.DisplayLoanTableAdapter.Fill(frmAddLoan.LibraryDataSet.DisplayLoan)
        frmAddLoan.ComboBox1.Update()
        MsgBox("Student Info Added")

    Else

        MsgBox("Student Name and Address have been used.")

    End If

End Sub
4

2 回答 2

2

尝试使用此代码。

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

    label1.Text = (ComboBox1.selectedIndex+1).ToString()

End Sub
于 2012-02-13T09:50:46.427 回答
0

这个怎么样?

label1.Text = ComboBox1.Items.Count.ToString();
于 2012-02-13T09:19:03.867 回答