0

我已将 ListBox 的 DisplayMember 设置为“Employee”列,并将 ValueMember 设置为“EmpID”列。列表框填充良好,但标签永远不会改变。我对此很陌生,无法弄清楚我错过了什么。这是我的代码:

Me.EmployeeTableAdapter.Fill(Me.TimeCards2DataSet.Employee)

Label1.Text = lstEmployees.SelectedItem.ToString
4

1 回答 1

0

您可能正在寻找 SelectedIndexChanged 事件:

Private Sub lstEmployees_SelectedIndexChanged(sender As Object, e As EventArgs) _
                         Handles lstEmployees.SelectedIndexChanged
  If lstEmployees.SelectedItem Is Nothing Then
    Label1.Text = String.Empty
  Else
    Label1.Text = lstEmployees.SelectedValue.ToString
  End If
End Sub

或者,如果使用 DataBinding:

Label1.DataBindings.Add("Text", Me.TimeCards2DataSet.Employee, "Employee")
于 2013-03-26T19:12:44.283 回答