为了保持简洁,我试图通过标签显示通过第二个表单上的组合框选择的数字。
以下是与我遇到的问题相关的位:
for i = 1 To 31
cmb_days.Items.Add(i)
next
' Populating combo box
days = cmb_days.text
frm_result.lbl_renting = "Renting for " & days & " Days"
我尝试过使用其他变种,例如cmb_days.selecteditem无效
我也有点问题就是告诉我的代码用组合框中实际选择的任何数字来做事情,idk我是非常新的
答案 0 :(得分:0)
That looks more or less correct.. But the question is where your call to update the label occurs in your code...
This is a minimal working example, with just a ComboBox on a form:
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
For i = 1 To 31
ComboBox1.Items.Add(i)
Next
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
Me.Text = ComboBox1.Text
End Sub
End Class
The update of the label (in this case the text of the form, but it works exactly the same with a label on a different form) occurs in the SelectedIndexChanged
event of ComboBox1.
If you copied your code straight from the project, you haven't had time to select anything yet, so the Text
property will be empty.