【问题标题】:Loading Combo Box from a table coulmn name that are numbers only从仅是数字的表列名称加载组合框
【发布时间】:2021-12-30 19:37:06
【问题描述】:

我有一个表,其列名仅为数字。 现在,我需要根据另一个名为“cboStandard”的组合框的选定值从该表中填充一个组合框,但 “无法创建字段 2 的子列表”会引发错误。 注意:表格列名由在 cboStandard 组合框中选择的值确定 下面是我填充组合框的代码:

**Dim Series As String = (cboStandard.Text).Substring((cboStandard.Text).IndexOf(" ") + 1, 3)
        If Not Series.Contains("Sys") Then
            Dim getWeights As String = "Select [" & Series & "] from StandardChicken where [" & Series & "] > 0 "
            loadcombo(getWeights, cboStandardWeights, Series)
            Dim dt As New DataTable()
            dt = ret.LoadDataTable2(getWeights)
            If Not (dt.Rows.Count = 0) Then
                cboStandardWeights.DataSource = dt
                cboStandardWeights.DisplayMember = Series
                cboStandardWeights.ValueMember = Series
                cboStandardWeights.AutoCompleteSource = AutoCompleteSource.ListItems
                

            ElseIf dt.Rows.Count = 0 Then
                cboStandardWeights.Text = ""
                cboStandardWeights.DataSource = dt
                cboStandardWeights.ValueMember = Series
                cboStandardWeights.DisplayMember = Series
                cboStandardWeights.AutoCompleteSource = AutoCompleteSource.ListItems
            End If**
 

【问题讨论】:

  • 我很困惑。你打电话给loadcomboloadcombo 中有什么内容?看来您以显示的方法加载组合框。 ret.LoadDataTable2中的代码呢
  • 请澄清您的具体问题或提供其他详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。

标签: sql vb.net combobox columnname


【解决方案1】:

执行以下操作:

private sub comboBox1_EditvalueChanged(sender As Object, e As EventArgs) Handles comboBox1.EditValueChanged
  dim myValue = CInt(comboBox1.EditValue)
  if myValue = 1 then
    'populate comboBox2
  else if myValue = 2
    'populate comboBox2 with other stuff
  end if
end sub

容易得多。你可以在里面做任何你想做的事情,你甚至可以隐藏和显示第二个组合框

【讨论】:

    猜你喜欢
    • 2021-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多