0
我有兩個datagridviewcombo列的datagrid,一列是動態填充,一列是固定的硬編碼值。 問題是我無法設置動態GridViewComboBox的值,當我嘗試設置它時會產生連續的錯誤。在Vb.net中設置Datagirdviewcombobox列值
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
請幫助我