Reputation: 125
What I want to do here is that for every new item added into the ComboBox
, a Label's text property will display +1 from the previous number.
How do I write it out, assuming I didn't assign the items a number.
Items Label
Tom 1
Jane 2
Mary 3
John 4
etc.. etc..
Edit: My ComboBox
is binded to a data source.
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
Upvotes: 1
Views: 2745
Reputation: 3751
Try using this code.
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
Upvotes: 2
Reputation: 3438
How about this?
label1.Text = ComboBox1.Items.Count.ToString();
Upvotes: 0