从绑定工具中填充TableAdapterStripComboBox
我想根据ToolStripComboBox中的选择来填充TableAdapter。 首先,我想通过将ToolStipComboBox绑定到数据源来填充ToolStipComboBox。然后一旦填满,我想填充TableAdapter。从绑定工具中填充TableAdapterStripComboBox
这是我的代码:
Private Sub ToolStripComboBox_MessageType_Click(sender As Object, e As EventArgs) Handles ToolStripComboBox_MessageType.Click Me.ToolStripComboBox_MessageType.ComboBox.DataSource = DataSet_UToolDb.XML_MESSAGE_TYPE
Me.ToolStripComboBox_MessageType.ComboBox.DisplayMember = "MessageType"
Me.ToolStripComboBox_MessageType.ComboBox.ValueMember = "MTId"
End Sub
Private Sub ToolStripComboBox_MessageType_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ToolStripComboBox_MessageType.SelectedIndexChanged
Me.TableAdapter_XML_MESSAGE_STRUCTURE.Fill(DataSet_UToolDb.XML_MESSAGE_STRUCTURE, Me.ToolStripComboBox_MessageType.ComboBox.SelectedValue)
End Sub
出于某种原因(如果我通过代码步骤)的代码从那里数据源设置的跳跃,到TableAdapter的填充。这是因为TableAdapter的select查询正在根据从ToolStipComboBox中选择的值查找值而导致异常。
回答:
我怀疑你的代码跳到TableAdapter被填充的位置,因为通过设置组合框的DataSource导致SelectedIndexChanged
事件被触发。
因此,如果ToolStripComboBox尚未填充,您需要告诉SelectedIndexChanged
处理程序返回,您可以通过在填充ToolStripComboBox时设置布尔标志来执行此操作。例如:
Dim m_ToolStripComboBoxPopulated As Boolean Private Sub ToolStripComboBox_MessageType_Click(sender As Object, e As EventArgs) Handles ToolStripComboBox_MessageType.Click
Me.m_ToolStripComboBoxPopulated = False
Me.ToolStripComboBox_MessageType.ComboBox.DataSource = DataSet_UToolDb.XML_MESSAGE_TYPE
Me.ToolStripComboBox_MessageType.ComboBox.DisplayMember = "MessageType"
Me.ToolStripComboBox_MessageType.ComboBox.ValueMember = "MTId"
' Indicate ToolStripComboBox has been populated
Me.m_ToolStripComboBoxPopulated = True
End Sub
Private Sub ToolStripComboBox_MessageType_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ToolStripComboBox_MessageType.SelectedIndexChanged
If (Me.m_ToolStripComboBoxPopulated = False) Then
Return
End If
Me.TableAdapter_XML_MESSAGE_STRUCTURE.Fill(DataSet_UToolDb.XML_MESSAGE_STRUCTURE, Me.ToolStripComboBox_MessageType.ComboBox.SelectedValue)
End Sub
以上是 从绑定工具中填充TableAdapterStripComboBox 的全部内容, 来源链接: utcz.com/qa/264419.html