更改 ComboBox 控件的 SelectedIndex 属性时如何更新标签的文本?
我在这里想要做的是,对于添加到 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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用此代码。
Try using this code.
这个怎么样?
How about this?