對不起,我是vb.net 2010新手。我也是新來的子類。該comobobox被用作查詢。vb.net Combobox重置爲未選定的時候失去焦點當綁定到Objectdatasource
我有一個綁定到bindingSource的comboxbox。問題出在我選擇了我的組合框上的一個項目並失去它的焦點後,它恢復爲空白。爲什麼是這樣?奇怪的。
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是我使用/編輯的用戶數據添加到數據庫中的表格。我仍然處於加入階段。沒有代碼可供編輯。
Combobox問題:每當我從UserTypeCombobox(例如「編碼器」)中選擇一個項目時,選擇將在失去焦點時恢復爲未選中狀態。 :-(
奇怪我嘗試了BindingSource.suspendBinding和BindingSource.ResumeBinding它似乎解決了這個問題。但編譯後,問題仍然存在。 :-( – user2059064