抱歉,我是 vb.net 2010 的新手。我也是子类化的新手。组合框用作查找。
我有一个绑定到 bindingSource 的组合框。问题是在我在组合框中选择一个项目并失去焦点后,它会恢复为空白。为什么是这样?诡异的。
My tables:
tblUsers
-FullName
-UserName
-Password
-UserTypeID
tblUserType
-UserTypeID
-UserType (Admin, Supervisor, Encoder)
My Class Library:
-Users.vb = table encapsulation of tblUsers
-UserDB.vb = methods for my tblUsers
-UserType.vb = table encapsulation of tblUserType
-UserTypeDB.vb = methods for my tblUserType
Data Sources:
-UserBindingSource = Users.vb Class
-UserTypeBindingSource = UserType.vb Class
Databindings for my UserTypeComboBox:
UserTypeComboBox.DataSource = UserTypeBindingSource
UserTypeComboBox.DisplayMember = UserType
UserTypeComboBox.ValueMember = UserTypeID
UserTypeComboBox.SelectedValue = UsersBindingSource - UserTypeID
My Code Below:
Public Class frmUsers_AddEdit
Private newUser As Users
Private usertypeList As List(Of UserType)
Private Sub LoadComboboxes()
Try
usertypeList = UserTypeDB.GetUserTypeList
UserTypeComboBox.DataSource = usertypeList
Catch ex As Exception
MessageBox.Show(ex.Message, ex.GetType.ToString)
End Try
End Sub
Private Sub frmUsers_AddEdit_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.LoadComboboxes()
UsersBindingSource.Add(newUser)
End Sub
end class
frmUsers_AddEdit 是我用来将用户数据添加/编辑到数据库中的表单。我还在添加阶段。还没有可编辑的代码。
组合框问题:每次我从 UserTypeCombobox(例如“编码器”)中选择一个项目时,当它失去焦点时,选择将恢复为未选中状态。:-(