0

2つのdatagridviewcombo列を持つdatagridがあり、1つの列は動的な塗りつぶしで、もう1つはハードコードされた値が固定されています。問題は、動的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

plsは私を助けます

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 に答える