У меня есть DataGridView (называемый DataGridViewSecurity) в VB.net (Visual Studio 2010), который привязан к DataTable (называемый DataTableSecurity) в наборе данных (называемый DataSetSecurity). Я добавил несвязанный столбец (названный nSecurityComboBox), который я установил на основе целочисленного поля (названного nSecLevel) в DataTable. После настройки поля со списком он ничего не отображает в поле со списком, но когда вы выбираете поле со списком, отображаются 5 значений в его коллекции элементов.
Вот код, который я использую для добавления записи в DataTable, а затем для установки поля со списком:
Sub Foo()
.
.
.
DataSetSecurity.Tables(0).Rows.Add(New Object() {sName, sID, sSec})
ComboCell_Select(nRow, 3, DataGridViewSecurity, sSecRecs.nSecLevel)
MessageBox.Show("Value for the combo set at " + DataGridViewSecurity.Rows(nRow).Cells(3).Value.ToString)
.
.
.
End Sub
Private Sub ComboCell_Select(ByVal dgvRow As Integer, _
ByVal dgvCol As Integer, _
ByRef DGV As DataGridView,
ByRef nComboBoxRow As Int16)
Try
Dim CBox As DataGridViewComboBoxCell = CType(DGV.Rows(dgvRow).Cells(dgvCol), DataGridViewComboBoxCell)
Dim CCol As DataGridViewComboBoxColumn = CType(DGV.Columns(dgvCol), DataGridViewComboBoxColumn)
CBox.Value = CCol.Items(nComboBoxRow)
DGV.UpdateCellValue(dgvCol, dgvRow)
'MessageBox.Show("New value in the combo box = " + CBox.Value.ToString)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
messagebox.show в Foo показывает правильное значение поля со списком, но ничего не отображается. Кто-нибудь видит, что я делаю неправильно?
Спасибо.
-NCGrimbo