我正在尝试以编程方式设置DataGridViewComboBox的值,当我填充网格时,但我一直收到一个关于无法对组合框进行排序的错误 - "具有DataSource集的ComboBox无法排序。使用基础数据模型对数据进行排序。"
我不是要对组合框的数据进行排序,我只是在执行Rows.Add函数时尝试设置值成员。
编辑**整个列应包含相同的组合框项,并且不是特定于行的。
Public Sub LoadComboBox()
Dim comboBox = New Dictionary(Of Integer, String)
Try
//myStepTable = data ' SQL query to get ID and Step
For Each row As DataRow In myStepTable.Rows
comboBox.Add(row.Item("StepID"), row.Item("Step"))
Next
'colStep is the defined name of the combobox column
colStep.DataSource = New BindingSource(comboBox, Nothing)
colStep.DisplayMember = "Value"
colStep.ValueMember = "Key"
End Sub
Public Sub LoadGrid()
LoadComboBox()
myDataTable = data 'SQL query to get row data
For Each row As DataRow In myDataTable.Rows
dgvRecipeSteps.Rows.Add(row.Item("RowID"), row.Item("StepID"))
Next
End Sub