0

I have datagrid with two datagridviewcombo column, one column is dynamic fill and one has fixed hardcoded values. The problem is I can't set the value of dynamic GridViewComboBox, when I try to set it generates continues errors.

System.FormateException: DataGridViewComboBoxCell Value is not valid.

My code to load the grid is

   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 help with me

Atif
  • 278
  • 1
  • 3
  • 16

1 Answers1

0

It seems like you're trying to assign the value to whatever there is on the cell rather than instantiate the object that resides in the cell and then assign its value. I would try something like this:

Dim vComboBoxColumn As DropDownList = DirectCast(GRDAntimicrobials.Rows(index).Cells("cmbAntibiotics"))
vComboBoxColumn.Value = dr("AntibioticsStatus").ToString
Saul Delgado
  • 167
  • 2
  • 7