0

我有带有两个 datagridviewcombo 列的数据网格,一列是动态填充,一列具有固定的硬编码值。问题是我无法设置动态 GridViewComboBox 的值,当我尝试设置它时会生成持续错误。

System.FormateException:DataGridViewComboBoxCell 值无效。

我加载网格的代码是

   Dim dt As DataTable
    dt = GetDataTable("Select valuecol,displayCol From mytable")  'GetDataTable gives me datatable
    cmbAntibiotics.DataSource = dt
    cmbAntibiotics.DisplayMember = "Antibiotics"
    cmbAntibiotics.ValueMember = "AntibioticsID"
    Dim Index As Integer

    Dim dgr As DataGridViewRow
    For Each dr As DataRow In dtFromDB.Rows 'This datatable is filled with database
        Index = dtFromDB.Rows.Count - 1
        GRDAntimicrobials.Rows.Add()
        GRDAntimicrobials.Rows(Index).Cells("cmbAntibiotics").Value = dr("AntibioticsID").ToString   'At this point it shows value (1,2,3) rather then showing its display members
        GRDAntimicrobials.Rows(Index).Cells("AntibioticsStatus").Value = dr("AntibioticsStatus").ToString
    Next

请帮帮我

4

1 回答 1

0

似乎您正在尝试将值分配给单元格上的任何内容,而不是实例化驻留在单元格中的对象然后分配其值。我会尝试这样的事情:

Dim vComboBoxColumn As DropDownList = DirectCast(GRDAntimicrobials.Rows(index).Cells("cmbAntibiotics"))
vComboBoxColumn.Value = dr("AntibioticsStatus").ToString
于 2011-06-17T13:26:53.260 回答