You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

从仅含数字列名的表加载ComboBox触发Child list for field 2错误如何解决

问题原因

"Child list for field 2 cannot be created" 错误的核心诱因是数据绑定顺序错误:你先为组合框赋值了DataSource,再设置DisplayMember和ValueMember,当列名为纯数字、和控件上一次缓存的绑定字段不匹配时,绑定解析逻辑就会抛出该错误。

修复方案

  • 调整绑定顺序:先设置DisplayMember、ValueMember,再赋值DataSource,让控件提前知道要绑定的字段名
  • 绑定前清空旧缓存:每次重新绑定前先把DataSource设为Nothing,清除上一次绑定的残留数据
  • 简化空数据处理逻辑:无匹配行时直接清空控件数据源即可,无需给空表做重复绑定
  • 移除重复绑定逻辑:原代码中的loadcombo如果也是给目标组合框做绑定的方法,直接删除该行即可,避免重复绑定冲突

修正后代码

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 "
    ' 先清空旧绑定缓存
    cboStandardWeights.DataSource = Nothing
    cboStandardWeights.Items.Clear()
    
    Dim dt As DataTable = ret.LoadDataTable2(getWeights)
    If dt.Rows.Count > 0 Then
        ' 先设置绑定字段,再赋值数据源,是修复的核心
        cboStandardWeights.DisplayMember = Series
        cboStandardWeights.ValueMember = Series
        cboStandardWeights.DataSource = dt
        cboStandardWeights.AutoCompleteSource = AutoCompleteSource.ListItems
    Else
        cboStandardWeights.Text = ""
        cboStandardWeights.AutoCompleteSource = AutoCompleteSource.None
    End If
End If

内容的提问来源于stack exchange,提问作者Abdul Jeleel Kolapo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.25 20:36:04