Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/403.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net BindingCompleteTestate—获取导致异常的字段_Vb.net_Data Binding - Fatal编程技术网

Vb.net BindingCompleteTestate—获取导致异常的字段

Vb.net BindingCompleteTestate—获取导致异常的字段,vb.net,data-binding,Vb.net,Data Binding,我正在动态创建一些控件并将它们绑定到数据库: '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(c

我正在动态创建一些控件并将它们绑定到数据库:

'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\u BindingComplete进行检查。例如,如果文本框中的格式应为数字,则我会得到一个messagebox:

  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

我想要的是控件名,如果不可能,则是导致错误的数据库中的列名。

我找到了解决方案:

MessageBox.Show("Error :" & e.ErrorText + vbCrLf & _
                        "Control : " & e.Binding.Control.Name.ToString + vbCrLf & _
                        "Field : " & e.Binding.BindingMemberInfo.BindingField.ToString + vbCrLf & _
                        "Info :" & e.Binding.BindableComponent.ToString + vbCrLf & _
                        "Correct Format :" & e.Exception.InnerException.TargetSite.DeclaringType.Name)