0
我創造了一些控件動態,並將其綁定到數據庫中的字段:BindingCompleteState - 獲取引起異常
'childElem is an XElement containing data for the control,
'dpBindingSource is the bindingSource Connected with the database
Select Case cntrl.GetType
Case GetType(TextBox)
Dim txt As TextBox
txt = DirectCast(cntrl, TextBox)
txt.DataBindings.Add(New Binding("Text", dpBindingSource, childElem.Element("Col_Source").Value, True))
AddHandler txt.TextChanged, AddressOf controlValueChanged
Case GetType(ComboBox)
Dim cbo As ComboBox
cbo = DirectCast(cntrl, ComboBox)
With cbo
.DataSource = dt 'datatable to fill the combo
.DisplayMember = childElem.Element("Display_Member").Value
.ValueMember = childElem.Element("Value_Member").Value
.DataBindings.Add(New Binding("SelectedValue",dpBindingSource, childElem.Element("Col_Source").Value , True))
End with
AddHandler cbo.SelectedIndexChanged, AddressOf controlValueChanged
End Select
所以,當我試圖更新我通過dpBindingSource_BindingComplete檢查。如果在例如文本框格式應爲數字,我得到一個消息框:
Private Sub dpBindingSource_BindingComplete(sender As Object, e As System.Windows.Forms.BindingCompleteEventArgs) Handles dpBindingSource.BindingComplete
If Not e.BindingCompleteState = BindingCompleteState.Success Then
MessageBox.Show(e.ErrorText)
End If
End Sub
我想有是該控件的名稱,如果這是不可能的,那麼從數據庫中列名,是造成錯誤。